Prepare analysis SonarScanner for MSBuild 5.7.2 null reference exception

Azure DevOps builds have started failing on the ‘Prepare Analysis on SonarCloud for Web’ step. This step, form our on-premise build agent fails with the following log;

2022-08-30T08:58:57.4381355Z ##[section]Starting: Prepare analysis on SonarCloud
2022-08-30T08:58:57.7357959Z ==============================================================================
2022-08-30T08:58:57.7358335Z Task         : Prepare Analysis Configuration
2022-08-30T08:58:57.7358680Z Description  : Prepare SonarCloud analysis configuration
2022-08-30T08:58:57.7358945Z Version      : 1.29.0
2022-08-30T08:58:57.7359141Z Author       : sonarsource
2022-08-30T08:58:57.7359542Z Help         : Version: 1.29.0. [More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarscanner-for-azure-devops/)
2022-08-30T08:58:57.7359973Z ==============================================================================
2022-08-30T08:59:01.4471987Z [command]F:\Azagent\A3\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.29.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe begin /k:iPSLAz_RNE_Web /o:ipsl-sonarcloudkey-devops-lspi
2022-08-30T08:59:01.8809468Z SonarScanner for MSBuild 5.7.2
2022-08-30T08:59:01.8811230Z Using the .NET Framework version of the Scanner for MSBuild
2022-08-30T08:59:02.0795347Z Pre-processing started.
2022-08-30T08:59:02.1901622Z Preparing working directories...
2022-08-30T08:59:02.6138455Z 09:59:02.605  Updating build integration targets...
2022-08-30T08:59:03.0797757Z 09:59:03.073  Fetching analysis configuration settings...
2022-08-30T08:59:03.5366244Z 09:59:03.526  Provisioning analyzer assemblies for cs...
2022-08-30T08:59:03.5376189Z 09:59:03.526  Installing required Roslyn analyzers...
2022-08-30T08:59:03.7189929Z 
2022-08-30T08:59:03.7190638Z ##[error]Unhandled Exception:
2022-08-30T08:59:03.7637494Z ##[error]System.NullReferenceException: Object reference not set to an instance of an object.
   at SonarScanner.MSBuild.PreProcessor.Roslyn.SubdirIndex.GetOrCreatePath(String key)
   at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.GetPluginResourceFiles(Plugin plugin)
   at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.InstallAssemblies(IEnumerable`1 plugins)
   at SonarScanner.MSBuild.PreProcessor.Roslyn.RoslynAnalyzerProvider.FetchAnalyzerPlugins(String language, IEnumerable`1 activeRules)
   at SonarScanner.MSBuild.PreProcessor.Roslyn.RoslynAnalyzerProvider.SetupAnalyzer(TeamBuildSettings teamBuildSettings, IAnalysisPropertyProvider sonarProperties, IEnumerable`1 rules, String language)
   at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.<FetchArgumentsAndRulesets>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

Similar build with Microsoft Hosted build agents (Cloud) appear to work ok.

Any suggestions?

Hi @Roadkingscot,

Thank you for opening this issue. Your feedback helps us improve our products. We will look at it as soon as possible. After we confirm the issue, we will add labels and put it in our backlog

In the meantime can you help us with some answers?

Azure DevOps builds have started failing

  • Did something changed recently on your setup?
  • Do you run multiple analysis pipelines on the same machines? If yes, did all started failing?
  • Can you please try deleting the contents of the %temp%/.sonarqube directory?
  • Can you please share the verbose logs for the begin step?

Thanks,
Costin

Hi, in answer to the questions raised;
Nothing has changed in our setup (i.e. our definitions for the ADO build pipelines.
Yes multiple pipelines on the same machines are failing.
We’ve tried deleting the contents of the temp sonarqube directory but this did not resolve the problem.
Can you please explain what you mean by the ‘verbose logs’ and where I may find them.

The only thing I am aware of from our end is that these ADO builds are running on self hosted, on premise, agents. These had been working successfully on a daily basis. Just before these failures the server concerned had been stopped, but it was then started again and all build agents on the server are showing as running. I believe a windows software patch had also been applied to the server.

Any suggestions for what we can try next?

I’ve carried out some further analysis and discovered the following;
It’s the call to SonarScanner.MSBuild.exe which is failing. The error for this on the Windows Event log is as follows;

Application: SonarScanner.MSBuild.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.NullReferenceException at SonarScanner.MSBuild.PreProcessor.Roslyn.SubdirIndex.GetOrCreatePath(System.String) at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.GetPluginResourceFiles(SonarScanner.MSBuild.PreProcessor.Roslyn.Plugin) at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.InstallAssemblies(System.Collections.Generic.IEnumerable`1<SonarScanner.MSBuild.PreProcessor.Roslyn.Plugin>) at SonarScanner.MSBuild.PreProcessor.Roslyn.RoslynAnalyzerProvider.FetchAnalyzerPlugins(System.String, System.Collections.Generic.IEnumerable`1<SonarScanner.MSBuild.PreProcessor.Roslyn.Model.SonarRule>) at SonarScanner.MSBuild.PreProcessor.Roslyn.RoslynAnalyzerProvider.SetupAnalyzer(SonarScanner.MSBuild.Common.TeamBuildSettings, SonarScanner.MSBuild.Common.IAnalysisPropertyProvider, System.Collections.Generic.IEnumerable`1<SonarScanner.MSBuild.PreProcessor.Roslyn.Model.SonarRule>, System.String) at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor+<FetchArgumentsAndRulesets>d__14.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor+<DoExecute>d__12.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor+<Execute>d__11.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) at SonarScanner.MSBuild.BootstrapperClass+<PreProcess>d__10.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) at SonarScanner.MSBuild.BootstrapperClass+<Execute>d__8.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) at SonarScanner.MSBuild.Program+<Execute>d__4.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) at SonarScanner.MSBuild.Program+<Execute>d__3.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) at SonarScanner.MSBuild.Program+<Main>d__2.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) at SonarScanner.MSBuild.Program.<Main>(System.String[])

It’s trying to use SonarScanner for MSBuild 5.8. with a build integrated with MSBuild.

The latest download in the ‘SonarCloudPrepare’ directory on the build server appears to be 1.26.1

The same build from other servers appears to be working ok, so what is the potential issue on this build server? Running out of options here so any guidance/help is greatly appreciated.

Hello @Roadkingscot

Could you please provide us the content of the %temp%/.sonarqube directory?

All the best,
@Caba_Sagi

Hi.
Not sure we have a %temp%/.sonarqube directory. Build agent is running under a specific user account on an on-premise server. Build agents run on an F drive on the server, and within that drive I can see the following sub directory;
_work_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.29.0\common

Within this directory there is a subdirectory named sonarqube that contains the following;


Is this what you are after?

The actual temp director under the user account is empty.

I’ve also now discovered the following under the user account which runs the SonarCloud analysis. The [user]\appdata\local\temp\sonarqube directory contains a single ‘resources’ directory containing a number of numbered sub directories. Too big to upload here though.

Hi Scot, could you please delete the folder and retrigger the build? also, if the problem persists could you please run dir -s > out.txt in the .sonarqube folder and send us the out.txt file zip?

It looks to me that the scanner is failing when copping the analyzer dlls and I suspect that the current state was corrupted.