Code Analysis Error Failed to load file or assembly "System.Net.Http, Version = 2.0.0.0 in MVC4 Web API

this problem is exactly the same as this post http://forums.asp.net/t/1807797.aspx/1?System+Net+ Http + is + not + found and this one https://stackoverflow.com> .

I have all the latest RTM cue ball. Started a new MVC 4 in .Net 4.5, the nuget package for WebAPI was added, and now my code analysis ended with the same error as in the link above.

CA0058 Runtime Code Analysis Error CA0058: Reference Assembly 'System.Net.Http, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a' was not found. This assembly is necessary for the analysis referenced by: C: \ Projects \ InHouse \ TimeRecorder \ StopGap \ TimeRec \ bin \ TimeRec.dll, C: \ Projects \ InHouse \ TimeRecorder \ StopGap \ packages \ Microsoft.AspNet.WebApi.Core. 4.0.20710.0 \ Lib \ net40 \ System.Web.Http.dll. [Errors and Warnings] - (Global)

From what I can find, it seems to have happened with RC versions because there was a conflict between the .NET 4.5 framework of System.Net.Http and the WebApi version of System.Net.Http.

The other answers on https://stackoverflow.com/a/3/4/5755/ ... talk about downgrading from .Net 4.5 to 4.0, for obvious reasons, this is not my preferred solution!

+28
asp.net-web-api
Aug 25 '12 at 9:20
source share
4 answers

Try the following:

  • Depending on the version of Visual Studio, go to:
    • VS 2010 :
      %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop
    • VS 2012 :
      %ProgramFiles(x86)%\Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\FxCop
  • Open FxCopCmd.exe.config and change AssemblyReferenceResolveMode from StrongName to StrongNameIgnoringVersion.
  • Save the changes and rebuild the project.
+71
Oct 11 '12 at 19:24
source

From Visual Studio 2012 and above, instead of modifying the installation files, use the workaround indicated here: Using Microsoft.Bcl.Async with code analysis causes errors .

+5
Aug 02 '13 at 18:35
source

I had the same problem (failed to create locally and remotely on azure). This workaround helped me: http://connect.microsoft.com/VisualStudio/feedback/details/760208/nuget-package-for-asp-net-mvc-4-web-api-does-not-reference-correct- net-4-5-assemblies #

here is the part you need:

Copy the System.Net.Http.dll and System.Net.Http.xml files contained in the \ Microsoft.Net.Http.2.0.20710.0 \ lib \ net40 directory into the \ Microsoft.AspNet.WebApi packages. Core.4.0.20710.0 \ lib \ net40. Since the missing assembly of System.Net.Http.dll is now in the same place as the link to the assembly of System.Web.Http.dll, code analysis can now correctly resolve the conflicting assembly of System.Net.Http.

+2
Apr 24 '13 at 10:25
source

The problem arises because you depend on a newer version of System.Net.Http than one of the other assemblies requires.

The correct way to solve this problem is to add dependentAssembly redirects to the abusive projects app.config . The accepted answer about disabling errors simply masks the main problem.

Add the following to the runtime section of app.config to reassign an old version that might not be allowed for the version specified in your project. Obviously, version numbers should be updated to suit your situation.

 <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> 
0
Nov 06 '13 at 21:21
source



All Articles