SonarQube scanner for MSBuild fails with a weird error

672 views
Skip to first unread message

Lior Tal

unread,
Dec 10, 2016, 12:59:28 PM12/10/16
to SonarQube
Hi,

I'm trying to scan our Unity3D project using the MSBuild scanner (from command line).
I am invoking it like as per the documentation: http://docs.sonarqube.org/display/SCAN/From+the+Command+Line

Spcifically, the build is executed in 3 steps:
1. A "begin" step
2. Invoking MSBuild to rebuild our .sln file
3. An "end" step

The build step fails with an error message:

"D:\Projects\MoonActive\Vikings\Vikings.sln" (Rebuild target) (1) ->
"D:\Projects\MoonActive\Vikings\Vikings.Editor.csproj" (Rebuild target) (4) ->
(RunCodeAnalysis target) ->
  MSBUILD : error : CA0001 : Could not find type 'UnityEngine.UI.Selectable' in assembly 'UnityEditor.UI, Version=1.0.0.0, Culture=neutral'. [D:\Projects\MoonActive\Vikings\Vikings.Editor.csproj]

    4421 Warning(s)
    1 Error(s)

I am building the project using this command:
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /t:Rebuild Vikings.sln


When invoking this MSBuild command without the prep "begin" step for the scanner, the build works just fine. So whatever is failing is not related to building our code.
I am not able to find the exact cause for this failure ...

Any help would be great (also - guidance how to diagnose this would be great).

Thanks
Lior
Message has been deleted
Message has been deleted
Message has been deleted

Lior Tal

unread,
Dec 11, 2016, 1:30:09 AM12/11/16
to SonarQube
I've created a small reproduction project that demonstrates this issue: https://dl.dropboxusercontent.com/u/31384095/Bugs/SonarQube/bug.zip

Unzip and run the "Reproduce.bat" file. Note that you'll need to edit it before running to make sure it points to the right location where you have the scanner installed.

-

Tamas Vajk

unread,
Dec 13, 2016, 4:03:39 AM12/13/16
to Lior Tal, SonarQube
Hello Lior,

Thanks for the repro. And here's what I have found:
If you run an analysis with the latest C# plugin then the analysis doesn't fail. Based on the CA... error that you get, I'm assuming that you have the SonarQube FxCop plugin, or you're using an older SonarQube C# plugin, which was embedding the FxCop analysis. So I ran FxCop inside Visual Studio (Analyze/Run Code Analysis/On Solution) and I did get the same issue you're experiencing. With a bit more detail:

  <Exception Keyword="CA0001" Kind="AssemblyLoad">
   <Type>Microsoft.FxCop.Common.AssemblyLoadException</Type>
   <ExceptionMessage>Could not find type 'UnityEngine.UI.Selectable' in assembly 'UnityEditor.UI, Version=1.0.0.0, Culture=neutral'.</ExceptionMessage>
   <StackTrace>   at Microsoft.FxCop.Engines.Phoenix.LoadAndResolutionHandler.HandleFailureToFindTypeDefinitionByName(ModuleUnit unit, UInt32 typeRefToken, String name)
   at Phx.Metadata.LoaderImplementation.GetTypeReferenceSymbol(UInt32 typeReferenceToken)
   at Phx.Metadata.LoaderImplementation.GetTypeReferenceSymbol(UInt32 typeReferenceToken)
   at Phx.Metadata.LoaderImplementation.GetSymbolByToken(UInt32 token)
   at Phx.Metadata.LoaderImplementation.GetTypeFromSignature(Byte*&amp; signature, TypeSymbol typeSpecificationSymbol, AggregateType variableAggregateType, FunctionSymbol variableFunctionSymbol)
   at Phx.Metadata.LoaderImplementation.MakeFunctionType(Byte*&amp; signature, TypeSymbol typeSymbol, AggregateType aggregateType, FunctionSymbol functionSymbol, UInt32 functionToken)
   at Phx.Metadata.LoaderImplementation.GetMethodDefinitionSymbol(UInt32 methodDefinitionToken)
   at Phx.Metadata.MetadataLoader.LoadTypeDefinitionMembers(TypeSymbol symbol)
   at Phx.Metadata.MetadataLoader.LoadMembers(Type type)
   at Microsoft.FxCop.Engines.Phoenix.AssemblyLoader.ProcessLoadingMembers(AggregateType type, RingModelExtension extension, MetadataLoader metadataLoader)
   at Microsoft.FxCop.Engines.Phoenix.AssemblyLoader.ProcessWorklist(MetadataLoader metadataLoader, Boolean ignoreErrors)
   at Microsoft.FxCop.Engines.Phoenix.AssemblyLoader.LoadAssembly(String filePath)
   at Microsoft.FxCop.Engines.Phoenix.PhoenixAnalysisEngine.AnalyzeInternal()
   at Microsoft.FxCop.Engines.Phoenix.PhoenixAnalysisEngine.Analyze()
   at Microsoft.FxCop.Common.EngineManager.Analyze(Project project, Boolean verboseOutput)</StackTrace>
  </Exception>

I also got the following note:
2>  NOTE: One or more referenced assemblies could not be found. Use the '/directory' or '/reference' switch to specify additional assembly reference search paths.

But this didn't lead me to any solutions. If you check the parameters of the FxCopCmd.exe that is being executed, everything seems fine (all assemblies are there, and there are no duplicate ones).

This issue seems like a bug in FxCop. I can't suggest any good solutions, but to disable FxCop rules and see if you can pinpoint the one that causes the issue.

Regards,
Tamas



Tamas VAJK | SonarSource
Language Team

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/0acb0333-1031-4ea6-8485-5e2f45b236e2%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Lior Tal

unread,
Dec 13, 2016, 5:54:44 PM12/13/16
to Tamas Vajk, SonarQube
Hi Tamas,

Thanks for your reply.

I am now running using the latest C# plugin version (5.5.1.522) but analysis still fails with the same error.
I also have the FxCop plugin installed (1.0). I think this is the correct one, and not the outdated version of it.

Next step i did was also to try running analysis from VS like you did - failed the same way as you mentioned.

Digging even deeper - the offending assembly UnityEditor.UI.dll originally references the required UnityEngine.UI.dll, but somehow gets processed to strip that assembly reference.
I believe this is the reason for failure. When executing the analysis, the "tampered" or modified DLL is used.


I reverted the DLL to the original version and everything works correctly.

So, not a SonarQube bug, but still annoying (and strange!)

Thanks for your help,
LT

Reply all
Reply to author
Forward
0 new messages