Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
579 views
in Technique[技术] by (71.8m points)

asp.net web api - Code Analysis error Could not 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 on StackOverflow

I have all the latest RTM bits, Started a new MVC 4 in .Net 4.5, added the WebAPI nuget package and now my code analysis fails with the same error as reported in the above link.

CA0058 Error Running Code Analysis CA0058 : The referenced assembly 'System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be found. This assembly is required for analysis and was referenced by: C:ProjectsInHouseTimeRecorderStopGapTimeRecinTimeRec.dll, C:ProjectsInHouseTimeRecorderStopGappackagesMicrosoft.AspNet.WebApi.Core.4.0.20710.0lib et40System.Web.Http.dll. [Errors and Warnings] - (Global)

From what I can find this seemed to happen with the RC versions because there was a conflict between the .NET 4.5 framework System.Net.Http and the WebApi's version of the System.Net.Http.

The other answers on the StackOverflow response talk about downgrading from .Net 4.5 to 4.0, for obvious reasons, this is not my preferred solution!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try the following:

  1. Depending on your Visual Studio edition navigate to:
    • VS 2010:
      %ProgramFiles(x86)%Microsoft Visual Studio 10.0Team ToolsStatic Analysis ToolsFxCop
    • VS 2012:
      %ProgramFiles(x86)%Microsoft Visual Studio 11.0Team ToolsStatic Analysis ToolsFxCop
  2. Open FxCopCmd.exe.config and change AssemblyReferenceResolveMode from StrongName to StrongNameIgnoringVersion.
  3. Save the change and rebuild your project.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...