1
votes

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

1 Answers

2
votes

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