Error CS0433 The type 'WebUtility' exists in two places

蹲街弑〆低调 提交于 2020-01-05 05:40:10

问题


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");

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.

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.

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'

Other posts I've seen about this issue ask for a project.json file, which I don't seem to have. Any thoughts?

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.


回答1:


I found the problem.

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.

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?)



来源:https://stackoverflow.com/questions/43757769/error-cs0433-the-type-webutility-exists-in-two-places

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!