Reported on the community forum: https://community.sonarsource.com/t/c-analysis-failing-in-azure-pipelines-due-to-java-lang-illegalargumentexception-uri-is-not-absolute/38995 . Project reproducer, logs and all information is present there.
The .CommandGenerator.cs files are indeed generated during build time. This is triggered by using the [GenerateCommand] attribute in WpfDemo/DemoViewModel.cs.
The SARIF report parsing is failing hard:
2021-02-23T21:59:23.4779322Z WARN: File 'Generators\Generators.CommandGenerator\GenerateCommandAttribute.cs' referenced by the protobuf 'MetricsInfo' does not exist in the analysis context
2021-02-23T21:59:23.5134921Z WARN: File 'Generators\Generators.CommandGenerator\DemoViewModel.CommandGenerator.cs' referenced by the protobuf 'MetricsInfo' does not exist in the analysis context
2021-02-23T21:59:23.5136692Z WARN: File 'Generators\Generators.CommandGenerator\GenerateCommandAttribute.cs' referenced by the protobuf 'TokenTypeInfo' does not exist in the analysis context
2021-02-23T21:59:23.5138016Z WARN: File 'Generators\Generators.CommandGenerator\DemoViewModel.CommandGenerator.cs' referenced by the protobuf 'TokenTypeInfo' does not exist in the analysis context
2021-02-23T21:59:23.5139426Z WARN: File 'Generators\Generators.CommandGenerator\GenerateCommandAttribute.cs' referenced by the protobuf 'SymbolReferenceInfo' does not exist in the analysis context
2021-02-23T21:59:23.5142730Z WARN: File 'Generators\Generators.CommandGenerator\DemoViewModel.CommandGenerator.cs' referenced by the protobuf 'SymbolReferenceInfo' does not exist in the analysis context
2021-02-23T21:59:23.5144461Z WARN: File 'Generators\Generators.CommandGenerator\GenerateCommandAttribute.cs' referenced by the protobuf 'CopyPasteTokenInfo' does not exist in the analysis context
2021-02-23T21:59:23.5145858Z WARN: File 'Generators\Generators.CommandGenerator\DemoViewModel.CommandGenerator.cs' referenced by the protobuf 'CopyPasteTokenInfo' does not exist in the analysis context
2021-02-23T21:59:23.5240639Z INFO: Importing 2 Roslyn reports
2021-02-23T21:59:23.8892188Z INFO: ------------------------------------------------------------------------
2021-02-23T21:59:23.9082600Z INFO: EXECUTION FAILURE
2021-02-23T21:59:23.9099757Z INFO: ------------------------------------------------------------------------
2021-02-23T21:59:23.9103004Z INFO: Total time: 43.754s
2021-02-23T21:59:23.9116543Z INFO: Final Memory: 27M/90M
2021-02-23T21:59:23.9118045Z INFO: ------------------------------------------------------------------------
2021-02-23T21:59:23.9119856Z ##[error]ERROR: Error during SonarScanner execution
2021-02-23T21:59:23.9121605Z ERROR: Error during SonarScanner execution
2021-02-23T21:59:23.9123175Z ##[error]java.lang.IllegalArgumentException: URI is not absolute
2021-02-23T21:59:23.9128841Z java.lang.IllegalArgumentException: URI is not absolute
2021-02-23T21:59:23.9130496Z ##[error]at java.base/java.io.File.<init>(File.java:418)
2021-02-23T21:59:23.9134877Z at java.base/java.io.File.<init>(File.java:418)
2021-02-23T21:59:23.9136986Z ##[error]at org.sonarsource.dotnet.shared.sarif.SarifParser10.uriToAbsolutePath(SarifParser10.java:225)
2021-02-23T21:59:23.9139038Z at org.sonarsource.dotnet.shared.sarif.SarifParser10.uriToAbsolutePath(SarifParser10.java:225)
2021-02-23T21:59:23.9140788Z ##[error]at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleLocation(SarifParser10.java:175)
2021-02-23T21:59:23.9142659Z at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleLocation(SarifParser10.java:175)
2021-02-23T21:59:23.9144410Z ##[error]at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleResultFileElement(SarifParser10.java:146)
2021-02-23T21:59:23.9146191Z at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleResultFileElement(SarifParser10.java:146)
2021-02-23T21:59:23.9147940Z ##[error]at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleLocationsElement(SarifParser10.java:138)
2021-02-23T21:59:23.9149709Z at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleLocationsElement(SarifParser10.java:138)
2021-02-23T21:59:23.9151397Z ##[error]at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleIssue(SarifParser10.java:107)
2021-02-23T21:59:23.9153212Z at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleIssue(SarifParser10.java:107)
2021-02-23T21:59:23.9155243Z ##[error]at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleIssues(SarifParser10.java:95)
2021-02-23T21:59:23.9157486Z at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleIssues(SarifParser10.java:95)
2021-02-23T21:59:23.9159270Z ##[error]at org.sonarsource.dotnet.shared.sarif.SarifParser10.accept(SarifParser10.java:65)
2021-02-23T21:59:23.9161073Z at org.sonarsource.dotnet.shared.sarif.SarifParser10.accept(SarifParser10.java:65)
2021-02-23T21:59:23.9162930Z ##[error]at org.sonarsource.dotnet.shared.sarif.SarifParser10.accept(SarifParser10.java:39)
2021-02-23T21:59:23.9164756Z at org.sonarsource.dotnet.shared.sarif.SarifParser10.accept(SarifParser10.java:39)
2021-02-23T21:59:23.9166545Z ##[error]at org.sonarsource.dotnet.shared.plugins.RoslynDataImporter.importRoslynReports(RoslynDataImporter.java:54)
2021-02-23T21:59:23.9168423Z at org.sonarsource.dotnet.shared.plugins.RoslynDataImporter.importRoslynReports(RoslynDataImporter.java:54)
2021-02-23T21:59:23.9170358Z ##[error]at org.sonarsource.dotnet.shared.plugins.DotNetSensor.executeInternal(DotNetSensor.java:111)
2021-02-23T21:59:23.9173852Z at org.sonarsource.dotnet.shared.plugins.DotNetSensor.executeInternal(DotNetSensor.java:111)
2021-02-23T21:59:23.9175845Z ##[error]at org.sonarsource.dotnet.shared.plugins.DotNetSensor.execute(DotNetSensor.java:71)
2021-02-23T21:59:23.9177777Z at org.sonarsource.dotnet.shared.plugins.DotNetSensor.execute(DotNetSensor.java:71)
Possibly relatated S4MSB test: E2E_IntermediateOutputFilesAreExcluded in E2EAnalysisTests.cs.
I've added a minimal reproducer here: https://github.com/costin-zaharia-sonarsource/source-generators-poc
During compilation Roslyn is producing virtual files which contain the generated code. These files does not exist on disk and the paths are not absolute. Due to this the Roslyn reports import fails.
ERROR: Error during SonarQube Scanner execution
java.lang.IllegalArgumentException: URI is not absolute
at java.base/java.io.File.<init>(File.java:416)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.uriToAbsolutePath(SarifParser10.java:225)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleLocation(SarifParser10.java:175)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleResultFileElement(SarifParser10.java:146)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleLocationsElement(SarifParser10.java:138)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleIssue(SarifParser10.java:107)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleIssues(SarifParser10.java:95)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.accept(SarifParser10.java:65)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.accept(SarifParser10.java:39)
at org.sonarsource.dotnet.shared.plugins.RoslynDataImporter.importRoslynReports(RoslynDataImporter.java:55)
FYI:
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> property can be used to enable the compiler to emit the files on disk. These files will be saved by default in obj\Debug\[target framework]\generated\, in the project where the generators are used and the output folder can be customized by setting CompilerGeneratedFilesOutputPath property.
The path specified in the Roslyn report ([assembly].RoslynCA.json) does not match the path on disk.
Should we report the mismatch to Roslyn? As the file exists and might have explicitly configured location, it would make sense to point the JSON content to the real emitted file.
Yes, that would be very useful. I will add an issue.
Is there a workaround in the meantime? Or are going to release this fix soon?
Hi @cmenzi, this fix was released 22 days ago in 8.20 version of the analyzer
https://github.com/SonarSource/sonar-dotnet/releases/tag/8.20.0.28934
Thank you for the fast response.
I'm using dotnet-sonarscanner version 5.10 which seems to be the current latest. Is it another repo or does it have another release cycle?
There are more components in the game: SonarQube/SonarCloud/Scanner/Analyzer.
If you're using SonarCloud, you should already have the fix.
If you're using SonarQube, this will be shipped with 8.9 release. There was a glitch in the last release that prevented it to be shipped with 8.8.
This doesn't depend on the scanner version.
Ok, I'm using SonarQube. Is there a workaround? The problem is that, that's a NuGet package is using those SourceGenerators and now all projects which are using this NuGet stopped working.
Just to understand the process:
Can I install the plugin manually on the server?
Just the output again.. I very appreciate your help, even the issue is already closed. 馃憤
ERROR: Error during SonarScanner execution
java.lang.IllegalArgumentException: URI is not absolute
at java.base/java.io.File.<init>(File.java:419)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.uriToAbsolutePath(SarifParser10.java:225)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleLocation(SarifParser10.java:175)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleResultFileElement(SarifParser10.java:146)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleLocationsElement(SarifParser10.java:138)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleIssue(SarifParser10.java:107)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.handleIssues(SarifParser10.java:95)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.accept(SarifParser10.java:65)
at org.sonarsource.dotnet.shared.sarif.SarifParser10.accept(SarifParser10.java:39)
at org.sonarsource.dotnet.shared.plugins.RoslynDataImporter.importRoslynReports(RoslynDataImporter.java:54)
at org.sonarsource.dotnet.shared.plugins.DotNetSensor.executeInternal(DotNetSensor.java:111)
at org.sonarsource.dotnet.shared.plugins.DotNetSensor.execute(DotNetSensor.java:71)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
at org.sonar.scanner.sensor.ProjectSensorsExecutor.execute(ProjectSensorsExecutor.java:49)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:361)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:144)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Ok, I got a workaround: https://stackoverflow.com/questions/66130258/disabling-a-specific-c-sharp-9-source-generator
I can exclude a specific SourceGenerator in the .csproj.
<Target Name="DisableSourceGenerator" BeforeTargets="CoreCompile">
<ItemGroup>
<Analyzer Remove="@(Analyzer)" Condition="'%(Filename)' == 'MyBreakingSourceGenerator'"/>
</ItemGroup>
</Target>
Maybe it helps somebody...
Thanks for the workaround, it might help other users indeed. On the other hand, if this is your only build, you won't profit from the source generator and it might produce different assembly than you expect.
You got the analysis process right. Unfortunately, you cannot update Analyzers on SQ. Analyzer versions are bundled with SQ release.