23

So I'm trying to run a bunch of rules which are defined in a RuleSet. The RuleSet file is actually generated using Sonarqube - I've selected absolutely all rules in there, including the FxCop, ReSharper and StyleCop rules. I'm kicking off FxCop like this:

C:/FxCop/FxCopCmd.exe /file:C:\TestProject\bin\TestProject.dll /ruleset:=C:\TestProject\testproject.ruleset /out:C:\TestProject\fxcop-report.xml /outxsl:none /forceoutput /searchgac /aspnet

It starts correctly, but I get the following message:

Initializing Introspection engine...
Analyzing...
Initializing Phoenix engine...
Analyzing...
Analysis Complete.
* 1 total analysis engine exceptions.

The XML output contains the following:

<Exception Keyword="CA0001" Kind="Engine">
    <Type>Phx.FatalError</Type>
    <ExceptionMessage>Exception of type 'Phx.FatalError' was thrown.</ExceptionMessage>
    <StackTrace>   at Phx.FatalError.Dispatch()
        at Phx.Logging.Diagnostics.DiagnosticMessage.LogMessage(Severity severity, DiagnosticInfo diagnosticInfo, SourceContext sourceContext, String descriptionString)
        at Phx.PE.PEUtilities.UserError(String infoMessage)
        at Phx.Pdb.ReaderImplementation.Open(Boolean loadTypeOnly)
        at Phx.PEModuleUnit.LoadPdb()
        at Phx.PE.ReaderPhase.CheckSymbolicInformation()
        at Phx.PEModuleUnit.LoadGlobalSymbols()
        at Phx.PEModuleUnit.LoadEncodedIRUnitList()
        at Phx.PEModuleUnit.GetEnumerableContributionUnit(ContributionUnitEnumerationKind contributionUnitEnumerationKind)
        at Phx.PEModuleUnit.GetEnumerableContributionUnit()
        at Microsoft.FxCop.Engines.Phoenix.PreScanPass.GetFunctionUnits(PEModuleUnit peModuleUnit)
        at Microsoft.FxCop.Engines.Phoenix.PreScanPass.Execute(ModuleUnit moduleUnit)
        at Phx.Passes.Pass.DoPass(ModuleUnit moduleUnit)
        at Phx.Passes.PassList.DoPassList(ModuleUnit moduleUnit)
        at Microsoft.FxCop.Engines.Phoenix.PhoenixAnalysisEngine.Host.ExecutePasses(PEModuleUnit peModuleUnit)
        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>

If I run the same command without the /aspnet flag I will still get the same error, but I do get the actual messages in the XML output file as well.

My end goal here is to run this from Sonarqube (using the Sonarqube runner in TeamCity), but I'm getting the exact same issues there as well. Starting the process from Teamcity I'm getting the following:

18:19:46][Step 4/4] INFO: ------------------------------------------------------------------------
[18:19:46][Step 4/4] INFO: EXECUTION FAILURE
[18:19:46][Step 4/4] INFO: ------------------------------------------------------------------------
[18:19:46][Step 4/4] Total time: 24.122s
[18:19:46][Step 4/4] ERROR: Error during Sonar runner execution
[18:19:46][Step 4/4] org.sonar.runner.impl.RunnerException: Unable to execute Sonar
[18:19:46][Step 4/4]    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
[18:19:46][Step 4/4]    at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
[18:19:46][Step 4/4]    at java.security.AccessController.doPrivileged(Native Method)
[18:19:46][Step 4/4]    at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
[18:19:46][Step 4/4]    at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
[18:19:46][Step 4/4]    at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
[18:19:46][Step 4/4]    at org.sonar.runner.api.Runner.execute(Runner.java:90)
[18:19:46][Step 4/4]    at org.sonar.runner.Main.executeTask(Main.java:70)
[18:19:46][Step 4/4]    at org.sonar.runner.Main.execute(Main.java:59)
[18:19:46][Step 4/4]    at org.sonar.runner.Main.main(Main.java:41)
[18:19:46][Step 4/4] Caused by: java.lang.IllegalStateException: The execution of "C:/FxCop/FxCopCmd.exe" failed and returned 1 as exit code. See http://msdn.microsoft.com/en-us/library/bb429400(v=vs.80).aspx for details.
[18:19:46][Step 4/4]    at com.google.common.base.Preconditions.checkState(Preconditions.java:145)
[18:19:46][Step 4/4]    at org.sonar.plugins.fxcop.FxCopExecutor.execute(FxCopExecutor.java:63)
[18:19:46][Step 4/4]    at org.sonar.plugins.fxcop.FxCopSensor.analyse(FxCopSensor.java:102)
[18:19:46][Step 4/4]    at org.sonar.plugins.fxcop.FxCopSensor.analyse(FxCopSensor.java:87)
[18:19:46][Step 4/4]    at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:59)
[18:19:46][Step 4/4]    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:51)
[18:19:46][Step 4/4]    at org.sonar.batch.phases.DatabaseModePhaseExecutor.execute(DatabaseModePhaseExecutor.java:120)
[18:19:46][Step 4/4]    at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:264)
[18:19:46][Step 4/4]    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
[18:19:46][Step 4/4]    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
[18:19:46][Step 4/4]    at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:235)
[18:19:46][Step 4/4]    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:230)
[18:19:46][Step 4/4]    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:228)
[18:19:46][Step 4/4]    at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:220)
[18:19:46][Step 4/4] Final Memory: 20M/428M
[18:19:46][Step 4/4] INFO: ------------------------------------------------------------------------
[18:19:46][Step 4/4]    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
[18:19:46][Step 4/4]    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
[18:19:46][Step 4/4]    at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:57)
[18:19:46][Step 4/4]    at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:45)
[18:19:46][Step 4/4]    at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:135)
[18:19:46][Step 4/4]    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
[18:19:46][Step 4/4]    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
[18:19:46][Step 4/4]    at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:158)
[18:19:46][Step 4/4]    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
[18:19:46][Step 4/4]    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
[18:19:46][Step 4/4]    at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:45)
[18:19:46][Step 4/4]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[18:19:46][Step 4/4]    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[18:19:46][Step 4/4]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[18:19:46][Step 4/4]    at java.lang.reflect.Method.invoke(Method.java:497)
[18:19:46][Step 4/4]    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
[18:19:46][Step 4/4]    ... 9 more
[18:19:46][Step 4/4] Process exited with code 1
[18:19:46][Step 4/4] Step SonarQube (SonarQube Runner) failed

This is using FxCop v12 installed on a box where there is no Visual Studio, in case that's of any importance...

Edit
The issue definitely is with the Phoenix analysis part - after disabling DFA rules described here it succeeds.

Trayek
  • 4,410
  • 3
  • 24
  • 39
  • What are the "actual messages in the XML output file" that you see when running without the `/aspnet` flag? Also, do you see the same problem when running FxCop directly against the target assemblies (as opposed to via Sonarqube)? – Nicole Calinoiu May 29 '15 at 16:20
  • Yes, I get the same problem when running FxCop directly. What I meant by the actual messages was that in the XML output file I can see a couple of the rules that should be fixed, followed by the exception – Trayek May 31 '15 at 07:40
  • Why are you using the `/aspnet` switch in this case? Is TestProject.dll an ASP.NET-generated assembly? Also, what does it reference? Are any of the references ASP.NET-generated assemblies? – Nicole Calinoiu Jun 03 '15 at 16:42

3 Answers3

51

Searching the Internet for the "Phx.FatalError" error, I found this blog post, in which the author basically says that doing a

regsrv32.exe msdia100.dll

(so apparently for VS2010 in his case), fixed the problem for him.

That lead me to the necessary hint what could have been the reason for the error on my machine.

I messed around on my DEV box with the Visual Studio Standalone Profiler setup [1]. I installed the profiling tools, that causes the contents of %ProgramFiles(x86)%\Microsoft Visual Studio 12.0\Team Tools\Performance Tools (from the original VS installation) to be replaced, which I was not aware of at the time. However, said setup also creates (or replaces) the %ProgramFiles(x86)%\Microsoft Visual Studio 12.0\Common7\Packages\Debugger\msdia120.dll file. That file is a COM server and is registered during setup (of Visual Studio or the Standalone Profiler package), which I also was not aware of.

Naturally, an uninstall of said Standalone Profiler package, uninstalls the files from the above directories and also unregisters msdia1xx.dll.

So, in my case the easiest fix was to reinstall in the Standalone Profiler package (x64 in my case) and everything worked again.

You might also be successful with just (re)registering your version of msdia1xx.dll [may need to be run as administrator]:

For Visual Studio 2010:

regsvr32 "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\msdia100.dll"

For Visual Studio 2012:

regsvr32 "%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\Common7\Packages\Debugger\msdia110.dll"

For Visual Studio 2013:

regsvr32 "%ProgramFiles(x86)%\Microsoft Visual Studio 12.0\Common7\Packages\Debugger\msdia120.dll"

For Visual Studio 2015:

regsvr32 "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\msdia140.dll"

For Visual Studio 2019 Enterprise:

regsvr32 "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\Common7\Packages\Debugger\msdia140.dll"

[1] Located on your VS installation media under <drive>:\Standalone Profiler or in your VS installation directory %ProgramFiles(x86)%\Microsoft Visual Studio <version>\Team Tools\Performance Tools\Setup.

Sreenath
  • 101
  • 1
  • 5
Christian.K
  • 47,778
  • 10
  • 99
  • 143
  • Thanks for this ;) – Alejandro Lora Mar 21 '17 at 09:47
  • 6
    I experienced this issue today after installing latest version of VS2019 (v16.8), and the solution appeared to resolve the problem (using a similar path to the VS2015 one shown above). – Ciaran Gallagher Nov 11 '20 at 16:09
  • 1
    @CiaranGallagher yeah, I have experienced the same problem today. Microsoft messed up some things again. – el_nektarin Nov 12 '20 at 13:31
  • @el_nektarin there's a thread about this issue here: https://developercommunity2.visualstudio.com/t/after-168-update-getting-lot-of-code-analysis-erro/1251574?from=email&viewtype=all There is a suggested solution/workaround there but I don't understand why all this is necessary. – Ciaran Gallagher Nov 16 '20 at 14:23
  • 1
    @CiaranGallagher yeah, I've already done it. It have resolved my issue, although I don't know whether the provided solution is needed for now or not since Microsoft released another new VS version 16.8.1 where they may have fixed the problem. – el_nektarin Nov 17 '20 at 00:38
  • 4
    I was facing same problem and It was fixed once I executed following command regsvr32 "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\Common7\Packages\Debugger\msdia140.dll" – Aneel Mehta Nov 18 '20 at 14:12
  • 3
    Registering the component helped me. Remember to run it in an administrator command prompt. – Palle Due Dec 09 '20 at 06:38
  • I ran this for Community edition: regsvr32 "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\Common7\Packages\Debugger\msdia140.dll" – Raghav Dec 12 '20 at 18:46
  • Or run this in VS dev command prompt: regsvr32 “%VSINSTALLDIR%\Common7\Packages\Debugger\msdia140.dll” So, you don't need to change path for Community, Professional or other editions. – Alex Blokha Feb 09 '21 at 14:04
  • Life saver! Thanks! If anyone needs the exact path for Professional VS 2019: regsvr32 "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\Common7\Packages\Debugger\msdia140.dll" – Dan Feb 10 '21 at 16:12
9

The answers posted here explain the issue and solutions well. This is to add context to how the problem can show up, in case future readers run into the Phx.FatalError exception the way I did:

In my case I still use VS 2017 Professional but have been exploring VS 2019 using the Community edition. I cloned a sizeable WPF solution from a client repo created using VS 2017. The solution builds fine in VS 2017, using default Debug and Release configurations. The same solution builds fine in VS 2019 using the Release configuration but threw the Phx.FatalError exception trying to rebuild using the default Debug configuration. Following the guidance I found here the following command (run as Administrator) solved the issue:

regsvr32 "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\Common7\Packages\Debugger\msdia140.dll

Thanks to the OP for the detailed description of the problem and to those providing the thorough answers.

Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51
1

this work for me regsvr32 "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\Common7\Packages\Debugger\msdia140.dll"

Adedamola
  • 11
  • 3