问题描述
我正在使用Visual Studio 2017创建一个asp.net核心应用程序.我正在尝试使用Web实用工具对URL组件进行编码.
I'm creating an asp.net core app using Visual Studio 2017. I'm trying to encode a URL component using web utility.
var value = System.Net.WebUtility.UrlEncode("some text here");
当我将其包含在代码中时,我看到以下错误.我不知所措.我看不到project.json文件.我已经搜索了包含System.Runtime.Extensions的任何地方.
When I include that in my code, I see the below error. I'm at a loss as to finding the issue. I see no project.json file. I have searched for anyplace where System.Runtime.Extensions are being included.
我安装了以下软件包:AspNetCore,AspNetCore.Mvc,AspNetCore.StaticFiles,.netCore.App,PaulMiami.AspNetCore.Mvc.Recaptcha
I have the following packages installed: AspNetCore, AspNetCore.Mvc, AspNetCore.StaticFiles, .netCore.App, PaulMiami.AspNetCore.Mvc.Recaptcha
我试图在不解决问题的情况下删除验证码软件包.
I have tried to remove the captcha package without it fixing the issue.
错误CS0433类型'WebUtility'在'System.Runtime.Extensions,Version = 4.1.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'和'System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'
Error CS0433 The type 'WebUtility' exists in both 'System.Runtime.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
有关此问题的其他帖子,我要求提供一个project.json文件,但我似乎没有.有什么想法吗?
Other posts I've seen about this issue ask for a project.json file, which I don't seem to have. Any thoughts?
更新1:我尝试创建一个新的asp.net核心Web应用程序-开箱即用的所有默认值,然后我安装了PaulMiami.AspNetCore.Mvc.Recaptcha程序包,对WebUtility的调用在新创建的应用程序中可以正常工作.在导致此问题的现有应用程序中一定找不到某些东西.
Update 1:I tried to create a new asp.net core web app - all defaults out of the box, I then installed the PaulMiami.AspNetCore.Mvc.Recaptcha package, the call to WebUtility works fine in the newly created app. There must be something I'm not finding in the existing application that is causing this issue.
推荐答案
我发现了问题.
在从属关系"下,我注意到程序集"的一个条目,在其中是系统"的一个条目.我不确定它是如何到达的,但是删除它后,我的问题消失了,应用程序得以编译.
Under "Dependencies" I noticed an entry for Assemblies, and in that was an entry for "System". I’m not sure how it got there, but after removing it my issue went away and the app compiles.
以后,我将确保检查此位置.值得注意的是,我创建的新创建的开箱即用的asp.net核心Web应用程序在依赖项"列表中没有程序集"条目.我必须先添加一个程序包,然后再将其删除,这导致了此问题. (也许是asp.net pre-.net核心验证码框架是错误的?)
In the future, I’ll be sure to check this location. Of note, the newly created out of the box asp.net core web app I created had no entry for Assemblies in the Dependencies list. I must have added a package and then removed it, which caused this issue. (perhaps the asp.net pre-.net core captcha framework by mistake?)
这篇关于错误CS0433类型"WebUtility"存在于两个地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!