Error CS0433 The type 'WebUtility' exists in two places - asp.net-core

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.

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

Related

.NET Core 2.1 Edit cshtml causes error during debug

In one of my VS 2017 instance, the same solution would required a shut down and rebuild when editing a cshtml file during debug. I have search google for a few days now and cannot find a solution.
This is the error:
An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
Generated Code
The type 'PartialTagHelper' exists in both 'Microsoft.AspNetCore.Mvc.TagHelpers, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' and 'Microsoft.AspNetCore.Mvc.TagHelpers, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
Check your NuGet dependencies and dependencies of the dependencies to figure out which of them is dependent on version 2.1.0.
As for fixing the issue there are the following options:
Update all the Microsoft.* NuGetpackages to 2.1.1 - should fix the
problem.
Or clean up the build outputs, NuGet cache, and delete .vs folder to
avoid any caching issues and then - rebuild again. If won't help,
get the repository sources to new directory from scratch.

RestSharp dll in SharePoint 2013

I am trying to make Rest Call through C#, to do that I am using RestSharp dll.
I have created farm level solution and added webpart, then installed RestSharp through NuGet.
The issue I am facing is in following line:
var client2 = new RestClient(webURL);
The moment I add this line, I am getting 'does not have strong name' error.
Referenced assembly 'RestSharp, Version=105.0.0.0, Culture=neutral, PublicKeyToken=null' does not have a strong name.
Then I created a console application added same dll and tried, it worked.
Then I created a simple web application and then added same dll and tried, it worked.
It is only failing when I am trying through webpart.
I really appreciate if anyone can guide me or give me some tip to solve this issue.
Have you tried signing your DLL with the key.snk file provided to you in your SharePoint project? Most of the time, 3rd party libraries need to be rebuilt with the snk file.
You just need to use ildasm to convert your dll to an .il file then use the ilasm to sign your il file with the snk file and convert it back to .dll
Let me know if you need more details regarding this.

Visual Studio 2017 - Could not load file or assembly 'System.IO.FileSystem

I just upgraded my Visual Studio to the latest version (1/30/2017).
My ASP.NET Core project was working before the upgrade, but I now get the following error that stops me. Are there any simple solutions to this?
Severity Code Description Project File Line Suppression State
Error MSB4018 The "ResolvePackageDependencies" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.NET.Build.Tasks.LockFileCache.LoadLockFile(String path)
at Microsoft.NET.Build.Tasks.LockFileCache.GetLockFile(String path)
at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.get_LockFile()
at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.ReadProjectFileDependencies()
at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
In my particular case, I did a Clean Solution, Tools/options/NuGet Package Manager/Clear All NuGet Cache(s), then a reboot. Loading/building the project then worked.
Not sure how repeatable this is. I'm quite sure my project worked the first time I loaded it, then failed, then worked again after these steps. It has worked on 2 computers.
I solved this by running dotnet build in the Paket-Manager Console of VS Studio.
After the software was again debuggable
The easiest way to fix this is to create a new ASP.NET Core application, check its .csproj file and modify the old project based on it. A lot of things seem to have been removed and simplified and it's too much to list here.

Could not load file or assembly 'AspNet.Loader, Version=1.0.0.0'

im using ASP.NET 5 MVC6, and i am getting this error whenever i try to run application:
An attempt was made to load an assembly from a network location which
would have caused the assembly to be sandboxed in previous versions of
the .NET Framework. This release of the .NET Framework does not enable
CAS policy by default, so this load may be dangerous. If this load is
not intended to sandbox the assembly, please enable the
loadFromRemoteSources switch. See
http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
and when i dive a little deeper in error i find this:
Could not load file or assembly 'AspNet.Loader, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies.
Operation is not supported.
I tryed googling it, but no luck, any ideas?
Thanks in advance!
I have had this issue when deploying to Azure as well. My only solution was to make sure the file and permissions on the folder wwwroot/bin are such that the server can see and access this directory.

Could not load file or assembly 'NetTopologySuite, Version=1.13.4693.18484

ok, here's the situation.
I have two projects:
ASP.NET MVC 4 (references class library)
Class Library (Added RavenDB and Net Topology Suite from NuGet)
When I try to run 'SpatialGenerate' in any index, I get the following error:
Could not load file or assembly 'NetTopologySuite, Version=1.13.4693.18484, Culture=neutral, PublicKeyToken=f580a05016ebada1' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I am using .net 4.5 of course and I'm doing this in VS 2012 on Windows 8. I have tried hosting this in IIS/IISexpress and the cassini server. I have checked that the file and it's related files are all present in the bin/debug directories and their versions are accurate. I also created a unit test that calls the queries via the index and I get the same error.
I have searched everywhere and I can't seem to find anything. Furthermore, once I was able to execute the index and everything worked, but I don't know why and can't make it happen again.
You need to use the RavenDB.Ebmedded package or add RavenDB.Database