17 September 2013 FxCop Robert Muehsig

Ich hatte kürzlich mit FxCop bzw. der Code Analyse unter Visual Studio 2012 ein Problem. Eines der WebApi NuGet Packages enthielt die Assembly “System.Net.Http”, allerdings sprang hierauf die Code Analyse an:

“CA0058 : The referenced assembly 'System.Net.Http, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be found. This assembly is required for analysis and was referenced by: C:\…\bin\Web.dll, C:\…\src\packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib


Problemlösung Variante 1 (direkt von dieser Stackoverflow Antwort) :

1.Go to "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop" or "%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\FxCop" if you have VS 2012.
2.Open FxCopCmd.exe.config and change AssemblyReferenceResolveMode from StrongName to StrongNameIgnoringVersion.
3.Save the change and rebuild your project.


Problemlösung Variante 2 (von Connect) und eine Erklärung für das Verhalten:

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.

Mit VS 2013 wurde die FxCop-Config aus Variante 1 genommen

In Visual Studio 2013 sollte dieses Problem nicht mehr auftreten, da die Standard-Einstellung nun auf “StrongNameIgnoringVersion” steht.

Written by Robert Muehsig

Software Developer - from Dresden, Germany, now living & working in Switzerland. Microsoft MVP & Web Geek.
Other Projects: KnowYourStack.com | ExpensiveMeeting | EinKofferVollerReisen.de

If you like the content and want to support me you could buy me a beer or a coffee via Litecoin or Bitcoin - thanks for reading!