Code Analysis error Could not load file or assembly 'System.Net.Http, Version=2.0.0.0 in MVC4 Web API

前端 未结 4 812
醉话见心
醉话见心 2020-12-13 06:42

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 on StackOverflow

I have all the latest

相关标签:
4条回答
  • 2020-12-13 07:09

    The issue is caused because you have a dependency on a newer version of System.Net.Http, than that required by one of the other assemblies referenced.

    The correct way to resolve this issue is to add dependentAssembly redirects to the app.config of offending projects. The accepted answer of disabling the errors just masks an underlying problem.

    Add the following to the runtime section of app.config to remap the old version that can't be resolved to the version referenced in your project. The version numbers should obviously be updated to correspond to 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 讨论(0)
  • 2020-12-13 07:16

    From Visual Studio 2012 and higher, instead of modifying your installation files, use the workaround specified here: Using Microsoft.Bcl.Async with Code Analysis causes errors.

    0 讨论(0)
  • 2020-12-13 07:21

    I have had the same problem (couldn't build 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 packages\Microsoft.Net.Http.2.0.20710.0\lib\net40 directory to the packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40 directory. Since the missing System.Net.Http.dll assembly is now in the same location as the referenced System.Web.Http.dll assembly, the code analysis can now properly resolve the conflicting System.Net.Http assembly.

    0 讨论(0)
  • 2020-12-13 07:22

    Try the following:

    1. Depending on your Visual Studio edition navigate 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
    2. Open FxCopCmd.exe.config and change AssemblyReferenceResolveMode from StrongName to StrongNameIgnoringVersion.
    3. Save the change and rebuild your project.
    0 讨论(0)
提交回复
热议问题