C# analysis failing in Azure Pipelines due to java.lang.IllegalArgumentException: URI is not absolute

I have just hit an issue with the SonarCloudAnalyze@1 task on Azure Pipelines, just after starting to use some source generators on my C# project. The full log is here; the part where it fails is:

WARN: File 'Generators\Generators.CommandGenerator\EditorTabViewModel.CommandGenerator.cs' referenced by the protobuf 'CopyPasteTokenInfo' does not exist in the analysis context
WARN: File 'Generators\Generators.CommandGenerator\IconTabViewModel.CommandGenerator.cs' referenced by the protobuf 'CopyPasteTokenInfo' does not exist in the analysis context
WARN: File 'Generators\Generators.CommandGenerator\MainWindowViewModel.CommandGenerator.cs' referenced by the protobuf 'CopyPasteTokenInfo' does not exist in the analysis context
INFO: Importing results from 5 proto files in 'D:\a\1\.sonarqube\out\15\output-cs'
INFO: Importing results from 5 proto files in 'D:\a\1\.sonarqube\out\4\output-cs'
INFO: Importing 15 Roslyn reports
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 51.309s
INFO: Final Memory: 28M/97M
INFO: ------------------------------------------------------------------------
##[error]ERROR: Error during SonarScanner execution
java.lang.IllegalArgumentException: URI is not absolute
ERROR: Error during SonarScanner execution
java.lang.IllegalArgumentException: URI is not absolute
##[error]at java.base/java.io.File.<init>(File.java:418)
	at java.base/java.io.File.<init>(File.java:418)
##[error]at org.sonarsource.dotnet.shared.sarif.SarifParser10.uriToAbsolutePath(SarifParser10.java:225)
	at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleLocation(SarifParser10.java:175)

All those X.CommandGenerator.cs files come from the source generator I am now using (this source generator is hosted on a separate project in the same repo).

Could these auto-generated files be causing the issue with the scanner? I tried to ignore them via sonar.exclusions=**/*.CommandGenerator.cs, but it seems it has no effect. The log still says 0 files ignored because of inclusion/exclusion patterns.

Hello @fernandreu ! Thank you for this bug report.

Would it be possible to provide a small reproducer project for this problem? It would speed up our investigation.

Are these files generated during build time?

Hi @Andrei_Epure ,

I took the time to create the simplified repo and demo pipeline and I am trying trying to share the links, but it seems I am getting automatically flagged for spam and I can’t post it (this seems a bit over the top). It is called sonarcloud-error on my GitHub profile. The pipeline is in the same Azure DevOps organisation as the other one, with the project being called SonarCloudDemo.

Essentially, there is a Generator project which contains the source generator, plus a demo Wpf app that makes use of it. The .CommandGenerator.cs files are indeed generated during build time. This is triggered by using the [GenerateCommand] attribute in WpfDemo/DemoViewModel.cs.

Thank you @fernandreu for the reproducer:

I opened an issue for us to investigate: C# analysis failing with source generators · Issue #4100 · SonarSource/sonar-dotnet · GitHub

Thanks a lot for taking the time to create the reproducer! It will help us investigate and provide a fix in a timely manner.

Best,
Andrei

1 Like