Sonar Cloud Azure DevOps Prepare Fails when run with multiple agents on same machine

It looks like there is an issue with having two agents using the Azure Devops Sonar Cloud Prepare Task on the same machine. See below.

2025-01-07T19:38:53.1292687Z ##[section]Starting: SonarCloudPrepare
2025-01-07T19:38:53.1299038Z ==============================================================================
2025-01-07T19:38:53.1299160Z Task         : Prepare Analysis Configuration
2025-01-07T19:38:53.1299246Z Description  : Prepare SonarQube Cloud analysis configuration
2025-01-07T19:38:53.1299327Z Version      : 3.1.1
2025-01-07T19:38:53.1299389Z Author       : sonarsource
2025-01-07T19:38:53.1299455Z Help         : [More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarcloud-extension-for-azure-devops/)
2025-01-07T19:38:53.1299625Z ==============================================================================
2025-01-07T19:38:53.6019303Z [INFO]  SonarQube Cloud: Server version: 8.0.0.58807
2025-01-07T19:38:53.6109052Z [command]C:\agent\agent-01\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\3.1.1\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe begin /k:myproject /o:myorg
2025-01-07T19:38:53.6627831Z SonarScanner for MSBuild 9.0.2
2025-01-07T19:38:53.6630026Z Using the .NET Framework version of the Scanner for MSBuild
2025-01-07T19:38:53.7064245Z Pre-processing started.
2025-01-07T19:38:53.7098580Z Preparing working directories...
2025-01-07T19:38:53.7767269Z 14:38:53.761  Updating build integration targets...
2025-01-07T19:38:54.9364249Z 14:38:54.934  Using SonarCloud.
2025-01-07T19:38:55.7603738Z 14:38:55.756  Fetching analysis configuration settings...
2025-01-07T19:38:56.8592167Z 14:38:56.849  Provisioning analyzer assemblies for cs...
2025-01-07T19:38:56.8597488Z 14:38:56.849  Installing required Roslyn analyzers...
2025-01-07T19:38:56.8601574Z 14:38:56.849  Processing plugin: csharpenterprise version 10.4.0.108396
2025-01-07T19:38:57.6609337Z 
2025-01-07T19:38:57.6609979Z ##[error]Unhandled Exception:
2025-01-07T19:38:57.6631627Z ##[error]System.IO.IOException: The file 'C:\Users\agent-account\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.CSharp.dll' already exists.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.IO.Compression.ZipFileExtensions.ExtractToFile(ZipArchiveEntry source, String destinationFileName, Boolean overwrite)
   at System.IO.Compression.ZipFileExtensions.ExtractToDirectory(ZipArchive source, String destinationDirectoryName)
   at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName, Encoding entryNameEncoding)
   at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.FetchResourceFromServer(Plugin plugin, String targetDir)
   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(BuildSettings teamBuildSettings, IAnalysisPropertyProvider sonarProperties, IEnumerable`1 rules, String language)
   at SonarScanner.MSBuild.PreProcessor.PreProcessor.<FetchArgumentsAndRuleSets>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.PreProcessor.PreProcessor.<DoExecute>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.PreProcessor.PreProcessor.<Execute>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.BootstrapperClass.<PreProcess>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.BootstrapperClass.<Execute>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.Program.<Execute>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.Program.<Execute>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.Program.<Main>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarScanner.MSBuild.Program.<Main>(String[] args)
2025-01-07T19:38:57.6637594Z System.IO.IOException: The file 'C:\Users\agent-account\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.CSharp.dll' already exists.
2025-01-07T19:38:57.6638062Z    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
2025-01-07T19:38:57.6638502Z    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
2025-01-07T19:38:57.6638909Z    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
2025-01-07T19:38:57.6639244Z    at System.IO.Compression.ZipFileExtensions.ExtractToFile(ZipArchiveEntry source, String destinationFileName, Boolean overwrite)
2025-01-07T19:38:57.6639465Z    at System.IO.Compression.ZipFileExtensions.ExtractToDirectory(ZipArchive source, String destinationDirectoryName)
2025-01-07T19:38:57.6639720Z    at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName, Encoding entryNameEncoding)
2025-01-07T19:38:57.6640083Z    at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.FetchResourceFromServer(Plugin plugin, String targetDir)
2025-01-07T19:38:57.6640306Z    at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.GetPluginResourceFiles(Plugin plugin)
2025-01-07T19:38:57.6640519Z    at SonarScanner.MSBuild.PreProcessor.Roslyn.EmbeddedAnalyzerInstaller.InstallAssemblies(IEnumerable`1 plugins)
2025-01-07T19:38:57.6640736Z    at SonarScanner.MSBuild.PreProcessor.Roslyn.RoslynAnalyzerProvider.FetchAnalyzerPlugins(String language, IEnumerable`1 activeRules)
2025-01-07T19:38:57.6640986Z    at SonarScanner.MSBuild.PreProcessor.Roslyn.RoslynAnalyzerProvider.SetupAnalyzer(BuildSettings teamBuildSettings, IAnalysisPropertyProvider sonarProperties, IEnumerable`1 rules, String language)
2025-01-07T19:38:57.6641617Z    at SonarScanner.MSBuild.PreProcessor.PreProcessor.<FetchArgumentsAndRuleSets>d__9.MoveNext()
2025-01-07T19:38:57.6641882Z --- End of stack trace from previous location where exception was thrown ---
2025-01-07T19:38:57.6642056Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2025-01-07T19:38:57.6642230Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2025-01-07T19:38:57.6642414Z    at SonarScanner.MSBuild.PreProcessor.PreProcessor.<DoExecute>d__7.MoveNext()
2025-01-07T19:38:57.6642632Z --- End of stack trace from previous location where exception was thrown ---
2025-01-07T19:38:57.6642795Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2025-01-07T19:38:57.6642970Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2025-01-07T19:38:57.6643156Z    at SonarScanner.MSBuild.PreProcessor.PreProcessor.<Execute>d__6.MoveNext()
2025-01-07T19:38:57.6643464Z --- End of stack trace from previous location where exception was thrown ---
2025-01-07T19:38:57.6643626Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2025-01-07T19:38:57.6643805Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2025-01-07T19:38:57.6643984Z    at SonarScanner.MSBuild.BootstrapperClass.<PreProcess>d__9.MoveNext()
2025-01-07T19:38:57.6644190Z --- End of stack trace from previous location where exception was thrown ---
2025-01-07T19:38:57.6644357Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2025-01-07T19:38:57.6644528Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2025-01-07T19:38:57.6644703Z    at SonarScanner.MSBuild.BootstrapperClass.<Execute>d__8.MoveNext()
2025-01-07T19:38:57.6644913Z --- End of stack trace from previous location where exception was thrown ---
2025-01-07T19:38:57.6645080Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2025-01-07T19:38:57.6645341Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2025-01-07T19:38:57.6645636Z    at SonarScanner.MSBuild.Program.<Execute>d__4.MoveNext()
2025-01-07T19:38:57.6646333Z --- End of stack trace from previous location where exception was thrown ---
2025-01-07T19:38:57.6646597Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2025-01-07T19:38:57.6646785Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2025-01-07T19:38:57.6646968Z    at SonarScanner.MSBuild.Program.<Execute>d__3.MoveNext()
2025-01-07T19:38:57.6647227Z --- End of stack trace from previous location where exception was thrown ---
2025-01-07T19:38:57.6647404Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2025-01-07T19:38:57.6647590Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2025-01-07T19:38:57.6647785Z    at SonarScanner.MSBuild.Program.<Main>d__2.MoveNext()
2025-01-07T19:38:57.6648000Z --- End of stack trace from previous location where exception was thrown ---
2025-01-07T19:38:57.6648173Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2025-01-07T19:38:57.6648359Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2025-01-07T19:38:57.6648534Z    at SonarScanner.MSBuild.Program.<Main>(String[] args)
2025-01-07T19:38:57.6739848Z ##[error][ERROR] SonarQube Cloud: Error while executing task Prepare: The process 'C:\agent\agent-01\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\3.1.1\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe' failed with exit code 3762504530
2025-01-07T19:38:57.6741042Z ##[error]The process 'C:\agent\agent-01\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\3.1.1\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe' failed with exit code 3762504530
2025-01-07T19:38:57.6821963Z ##[section]Finishing: SonarCloudPrepare

Hello @groogiam

Running two agents on the same machine is a scenario we do not support. It also is a configuration that is discourage by Microsoft:

Although multiple agents can be installed per machine, we strongly suggest to only install one agent per machine. Installing two or more agents might adversely affect performance and the result of your pipelines.

Source

You can find more details about why multiple agents are causing problems here Multi job Azure DevOps Pipeline - #3 by mickaelcaro.