This page is a work in progress. Do not hesitate to share your tips and tricks to improve this page.
If you encounter any trouble analyzing a C# project, first try to rerun the analysis adding "-X" to the command line in order to get a verbose output then ask for help to the users mailing list. Please do not open a JIRA ticket before sending emails to the users mailing list.
- Analysis succeed but tests metrics do not appear in the sonar dashboard
- Analysis succeed but too few violations are found
- Analysis succeed but only one test assembly/project is taken into account
- 0% code coverage using reuse reports mode
- OpenCover is activated and Gallio fails without any explanation
- When using OpenCover with Gallio, I get 0% code coverage whereas I do have test classes that are covered by tests
- Gallio execution fails with following error message
- Gallio execution fails on a Windows 64bits system
- Some tests fail unexpectedly using a legacy .net2 library
- Why do I get MSBuild error such as "error MSB4126: The specified solution configuration "Debug|HPD" is invalid"
- On Windows7 I get "The Silverlight 3/4 SDK is not installed" error messages
- The analysis fails with an OutOfMemory exception
- I get many false positives for gendarme rule AvoidVisibleFieldsRule
Analysis succeed but tests metrics do not appear in the sonar dashboard
Obviously this happens when Gallio has failed during the sonar analysis. There are several possible causes, below a few of them :
- You are running the analysis on a 64b box using partcover. Please follow the FAQ page in order to solve the problem with command line corflag tool.
- The test framework used by the analyzed Visual Studio solution is incompatible with the version of Gallio used during the analysis. This happens if you are using a quite old version of Gallio with a brand new version of Nunit. Easy fix : upgrade Gallio.
- The coverage tool (i.e. NCover, Partcover...) has failed during test execution. Again check the verbose logs. Changing the gallio runner config property may help in this case.
For example, if you are using MsTest and if you get Microsoft.VisualStudio.TestTools.TestManagement.InvalidStorageExtensionException error messages, try to rerun the analysis setting property sonar.gallio.runner to IsolatedProcess (thanks mathieu Lagace for the tip)
Analysis succeed but too few violations are found
Some tools like FxCop or Gendarme need compiled assemblies to perform analysis. In other words, they do not work on source code. Having too few violations most often comes from the following reasons:
- the Visual Studio solution hasn't been compiled prior to the Sonar analysis - whereas this is clearly mentionned in the documentation that it should
- the solution has been compiled but the corresponding generated assemblies have been moved somewhere else (because of a specific build process) and Sonar can't find them
- the solution has been compiled and the assemblies haven't been moved, but the whole solution folder has been moved to another location (and therefore the debug PDB files don't point to the original source locations)
Analysis succeed but only one test assembly/project is taken into account
If you are using NCover, you may have purchase the "Classic edition". Only the "Complete edition" allows to run tests from several assemblies and merge the coverage data. The good news is that version 1.2 of the sonar C# plugins brings a workaround. You can activate the "gallio safe mode" and the sonar gallio plugin will merge the coverage data. See the gallio config page for more details on this.
0% code coverage using reuse reports mode
This might happen if you have generated the reports then moved the files of your Visual Studio solution. In the XML coverage files, the paths to the C# source files must be the same as the paths specified in the csproj files of the analyzed solution, otherwise the coverage date are simply not taken in account.
OpenCover is activated and Gallio fails without any explanation
OpenCover needs .net framework 4 in order to run. If you try to use OpenCover without .net4 installed, the analysis will crash.
When using OpenCover with Gallio, I get 0% code coverage whereas I do have test classes that are covered by tests
Most probably, you should use the following property to run the tests in an isolated process:
Gallio execution fails with following error message
This error happens when one of the dotnet config files (app.config, web.config, ...) of your Visual Studio solution specifies a runtime version not supported by the instance of Gallio used. This is often the case when the following XML fragment appears in a app.config file:
The "sku" attribute is not something understandabe by Gallio... If you remove the above XML fragment by the one below the problem is solved :
Thanks a lot to Stéphane Lopes for the tip.
Gallio execution fails on a Windows 64bits system
If in the logs you get something such as:
that might be because some of your assemblies have been compiled with a x86 profile (32 bits) while Gallio is configured to run in an "Any CPU" mode, hence 64bits on your system.
This problem might be solved using corflags tool to force Gallio to run in a 32 bits mode as shown below:
Some tests fail unexpectedly using a legacy .net2 library
If you get this kind of error :
There are strong chances you are in the situation described here
The problem might be solved if you modify your installation of gallio. Add the following XML fragment in files Gallio.Host.x86.exe.config and/or Gallio.Host.x64.exe.config :
Why do I get MSBuild error such as "error MSB4126: The specified solution configuration "Debug|HPD" is invalid"
You are using a 64 bit windows OS. There is an environment variable "Platform=HPD" that makes msbuild fail. Try to run "set platform=[enter]" then "mvn sonar:sonar..."
On Windows7 I get "The Silverlight 3/4 SDK is not installed" error messages
64bits msbuild cannot be used with silverlight. Check that you are not using a 64bits msbuild by taking a look at properties dotnet.3.5.sdk.directory anddotnet.4.0.sdk.directory. "Framework64" should not be present in the path.
The analysis fails with an OutOfMemory exception
The java process performing the code analysis might need more RAM. Use the "-Xmx" option to specify the amount of memory that can be use. See the Sonar Runner documentation for more details
I get many false positives for gendarme rule AvoidVisibleFieldsRule
This rule works at class level. If you are working on a windows form or asp.net project, you may have many partial classes. The code generated in the "designer" parts may contain many "visible fields" whereas the real code that matters does not contain any defects. In order to avoid these false positives, you have two options:
- disable this rule. Probably not the best option
- Use the switch off violation plugin to disable the rule only on "view" related components.
On an asp.net project you may configure the switch off violation plugin as follow: