Reputation: 1090
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.
Upvotes: 10
Views: 9320
Reputation: 3462
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.
Upvotes: 1
Reputation: 714
The other answers are all on the right track but miss one small part.
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.
Upvotes: 6
Reputation: 1
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
Upvotes: 0
Reputation: 7636
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" />
Upvotes: 5
Reputation: 11277
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.
Upvotes: 0
Reputation: 19020
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
)
Upvotes: 1