10

While refactoring, moving around some assemblies around, etc. I compiled a solution in Visual Studio and got back a single error message: "FxCop exited with error code 512". The build seems fine other than this one error.

Anyone know what this actually means in detail? Where might I start looking to figure out how to fix it? Setting FailOnError to false is not a path I want to go down.

4
  • Dumb question, but related to ChrisWue's answer: Have you tried restarting VS? Maybe it has something to do with which assemblies are loaded/which assemblies can't be unloaded. Not sure if FxCop loads assemblies into VS's app domain, but I've seen other plugins/applications do this. Oct 31, 2011 at 3:24
  • Not a dumb question at all (just a dumb IDE that frequently needs to be restarted, lol). Yes I have tried it.
    – Nick W.
    Oct 31, 2011 at 3:45
  • Did you find a solution to this? I'm getting the same issue
    – magritte
    Sep 27, 2012 at 15:55
  • Magritte, I've had success using the answer by JohnDRoach.
    – Klee
    May 24, 2013 at 6:18

6 Answers 6

6

The other answers are all on the right track but miss one small part.

  • Suppressing is an option but you might hide an error regarding an important dll and that's not a good thing.
  • Random dependency directory is prone to error.
  • Xml reports are the place to look but the FxCop MSBuild Task doesn't reveal where it puts them :(

In order to run FxCop from the command line I had to execute the following:

FxCopCmd.exe /f:<Assembly.dll> /o:<OutputFileName> /verbose

FxCopCmd is what is MSBuild Task uses. It will return error code 512 if there is a missing assembly even if the assembly is not needed for it to run. See the below FxCop message:

The indirectly-referenced assembly 'Newtonsoft.Json, Version=4.0.2.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' could not be found. This assembly is not required for analysis, however, analysis results could be incomplete. This assembly was referenced by: Removed.dll.

Add the reference to that dll and then the error code disappears.

5

I found a solution. It was because I was referencing an assembly with a higher version and FxCop was complaining about it with warning CA0060 further down. The solution is to edit the FxCopCmd.exe.config file and change

<add key="AssemblyReferenceResolveMode" value="StrongName" />

to

<add key="AssemblyReferenceResolveMode" value="StrongNameIgnoringVersion" />
1

According to MSDN this means that it failed to reference some assembly. This guy suggests to override it with (I quote from his blog):

The following can be placed directly into the Post-build event field in your project's properties.
<YOUR FXCOP COMMAND>
IF 512 == %ERRORLEVEL% (
    echo postbuildevent:fxcop warning FXCOP:FxCopCode analysis was unable to complete.
    SET ERRORLEVEL = 0
) 
3
  • Yeah, I found that blog too but wasn't sure if it was such a good idea to effectively suppress the error without knowing what was causing it. After all, FxCop is meant to catch things that are bad, but still compile.
    – Nick W.
    Oct 31, 2011 at 3:20
  • @Nick W. Well if it is an assembly reference error then turning on Fusion logging might help to find out which assembly it can't find.
    – ChrisWue
    Oct 31, 2011 at 3:30
  • Thanks for the tip, but no dice. I tried turning on full fusion logging then re-running the compilation. I got a bunch of binds on FxCopCmd.exe, but all report successful completion.
    – Nick W.
    Oct 31, 2011 at 3:44
1

FxCop error code 512 arise if the sonar runner does not found the dependent assemblies location: For resolving this error you have to set the assemblyDependencyDirectories Property in Sonar-Runner. The value of this should be the comma-separated list of path patterns to locate the directories where dependency assemblies can be found.

These paths can be absolute or relative, the starting point being the folders where the csproj files are located. Also the special key $(SolutionDir) can be used to build a path relative to the root folder of the solution (i.e. where the sln file is located).

E.g.: $(SolutionDir)/**/libs (and not $(SolutionDir)/**/libs/*.dll)

E.g.: sonar.fxcop.assemblyDependencyDirectories=$(SolutionDir)/**/libs,$(SolutionDir)/**/Debug

For detailed solution and resolution of some more sonar runner error click here.

0

The first place to look for extra information is the XML report file -- that usually has some helpful information near the end.

Failing that, the other technique I've used in cases like this is to make the same query in the FxCop GUI; that will pop up a dialog when it fails to resolve an assembly reference, asking you to point at the relevant assembly. Knowing which assembly it is makes adding the extra directory path much easier.

0

Not sure if you're still looking for a solution but what usually works for me is adding the fxcop cmdline-option /d:{dir-of-random-assemblies} which essentially tells fxcop to look in that additional directory for assemblies. Adding a reference to a proj that doesn't need it is a bad idea in my opinion. This is a also a non-hacky way of taking care of the problem.

http://msdn.microsoft.com/en-US/library/bb429449(v=vs.80).aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.