Azure DevOps: "Prepare analysis" task crashes on Linux agent

Hi,

I’m using SonarQube vsts extension in Azure DevOps on .NET Core project.
Solution contains just a single minimal project (console app created using dotnet init).
Using “Hosted Ubuntu 16.04” agent pool, the build fails on “Prepare analysis” task.
Using otherwise exactly same configuration, our setup works using Hosted VS2017 agent.

  • Error: System.ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.
  • TargetFramework: netcoreapp2.1
  • SonarQube version: 7.5-community
  • SonarQube vsts extension version: 4.5.1

Log:

2019-01-25T12:28:43.1060018Z Task         : Prepare Analysis Configuration
2019-01-25T12:28:43.1060066Z Description  : Prepare SonarQube analysis configuration
2019-01-25T12:28:43.1060253Z Version      : 4.5.1
2019-01-25T12:28:43.1060333Z Author       : sonarsource
2019-01-25T12:28:43.1060382Z Help         : [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
2019-01-25T12:28:43.1060433Z ==============================================================================
2019-01-25T12:28:45.4873271Z SYSTEMVSSCONNECTION exists true
2019-01-25T12:28:46.3556620Z [command]/usr/bin/dotnet /home/vsts/work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.5.1/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll begin /k:sonar-test-project
2019-01-25T12:28:50.4813928Z SonarScanner for MSBuild 4.5
2019-01-25T12:28:50.4814679Z Using the .NET Core version of the Scanner for MSBuild
2019-01-25T12:28:52.4215593Z Default properties file was found at /home/vsts/work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.5.1/dotnet-sonar-scanner-msbuild/SonarQube.Analysis.xml
2019-01-25T12:28:52.4217112Z Loading analysis properties from /home/vsts/work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.5.1/dotnet-sonar-scanner-msbuild/SonarQube.Analysis.xml
2019-01-25T12:28:52.4224092Z Pre-processing started.
2019-01-25T12:28:52.4239077Z Preparing working directories...
2019-01-25T12:28:52.8595600Z 12:28:52.858  Updating build integration targets...
2019-01-25T12:28:52.9212844Z ##[error]Unhandled Exception:
2019-01-25T12:28:52.9224416Z 
2019-01-25T12:28:53.1795421Z ##[error]System.ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.
   at System.Reflection.RuntimeMethodInfo.CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags, StackCrawlMark& stackMark)
   at System.Reflection.RuntimeMethodInfo.CreateDelegate(Type delegateType)
   at System.Environment.<>c.<GetFolderPathCore>b__52_0()
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Func`1 valueFactory)
   at System.Environment.GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
   at System.Environment.GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
   at SonarScanner.MSBuild.Common.MsBuildPathSettings.<GetLocalApplicationDataPaths>d__8.MoveNext()
   at System.Linq.Enumerable.DistinctIterator`1.MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at SonarScanner.MSBuild.Common.MsBuildPathSettings.GetImportBeforePaths()
   at SonarScanner.MSBuild.PreProcessor.TargetsInstaller.InternalCopyTargetsFile()
   at SonarScanner.MSBuild.PreProcessor.TargetsInstaller.InstallLoaderTargets(String workDirectory)
   at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.DoExecute(ProcessedArgs localSettings)
   at SonarScanner.MSBuild.BootstrapperClass.PreProcess()
   at SonarScanner.MSBuild.BootstrapperClass.Execute()
   at SonarScanner.MSBuild.Program.Execute(String[] args, ILogger logger)
   at SonarScanner.MSBuild.Program.Main(String[] args)
2019-01-25T12:28:53.1796233Z System.ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.
2019-01-25T12:28:53.1796325Z    at System.Reflection.RuntimeMethodInfo.CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags, StackCrawlMark& stackMark)
2019-01-25T12:28:53.1796441Z    at System.Reflection.RuntimeMethodInfo.CreateDelegate(Type delegateType)
2019-01-25T12:28:53.1796504Z    at System.Environment.<>c.<GetFolderPathCore>b__52_0()
2019-01-25T12:28:53.1796908Z    at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Func`1 valueFactory)
2019-01-25T12:28:53.1796990Z    at System.Environment.GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
2019-01-25T12:28:53.1797078Z    at System.Environment.GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
2019-01-25T12:28:53.1797246Z    at SonarScanner.MSBuild.Common.MsBuildPathSettings.<GetLocalApplicationDataPaths>d__8.MoveNext()
2019-01-25T12:28:53.1797327Z    at System.Linq.Enumerable.DistinctIterator`1.MoveNext()
2019-01-25T12:28:53.1797389Z    at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToList()
2019-01-25T12:28:53.1797485Z    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
2019-01-25T12:28:53.1797548Z    at SonarScanner.MSBuild.Common.MsBuildPathSettings.GetImportBeforePaths()
2019-01-25T12:28:53.1797612Z    at SonarScanner.MSBuild.PreProcessor.TargetsInstaller.InternalCopyTargetsFile()
2019-01-25T12:28:53.1797720Z    at SonarScanner.MSBuild.PreProcessor.TargetsInstaller.InstallLoaderTargets(String workDirectory)
2019-01-25T12:28:53.1797789Z    at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.DoExecute(ProcessedArgs localSettings)
2019-01-25T12:28:53.1797893Z    at SonarScanner.MSBuild.BootstrapperClass.PreProcess()
2019-01-25T12:28:53.1797959Z    at SonarScanner.MSBuild.BootstrapperClass.Execute()
2019-01-25T12:28:53.1798060Z    at SonarScanner.MSBuild.Program.Execute(String[] args, ILogger logger)
2019-01-25T12:28:53.1798121Z    at SonarScanner.MSBuild.Program.Main(String[] args)
2019-01-25T12:28:57.6517326Z ##[error]/usr/bin/dotnet failed with return code: null
2019-01-25T12:28:57.6676002Z ##[section]Finishing: Prepare analysis on SonarQube
2019-01-25T12:28:57.6720967Z ##[section]Starting: Checkout

Hi @dorny, this seems to happen when we do Environment.GetFolderPath(SpecialFolder.UserProfile, SpecialFolderOption.Create) or Environment.GetFolderPath(SpecialFolder.LocalApplicationData, SpecialFolderOption.Create). I suspect the exception is related to insufficient permissions of the Scanner for MSBuild process to create those folders or something similar. We haven’t received similar bug reports so far and it would be difficult to investigate without a consistent way to reproduce the problem.

@dorny, I had the same issue and as a workaround I executed two commands before the SonarQube analysis task, after that it started without failures.

mkdir -p ~/.local/share
chmod 777 ~/.local/share

FYI it’s probably caused by this .NET Core issue.

I’ve created a ticket on our side to track it: S4MSB #681

1 Like