Dotnet-sonarscanner fails with "Invalid project key" with latest .NET 6 SDK on Linux

We use dotnet-sonarscanner on Linux as part of a GitHub Actions workflow.

We updated our runner image today to latest patches etc, after which running the tool to start a new scan started to fail with the following error:

14:39:51.486  14:39:51.486  Invalid project key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.
14:39:51.487  Expecting at least the following command line argument:
- SonarQube/SonarCloud project key

The key had not been changed, nor the code that invoked the tool, nor the version of the tool, and the key is valid.

Before the runner upgrade, the invocation worked. When the runner image update was reverted to the previous version, it started to work again.

Investigation showed that the previous image had the .NET 6.0.9 runtime and .NET 6.0.109 SDK installed. Unfortunately we don’t have access to the Docker image build logs anymore since the container was built to get the full logs.

The updated version of the image from today installs the following packages:

Reading state information...
The following additional packages will be installed:
  aspnetcore-runtime-6.0 aspnetcore-targeting-pack-6.0 dotnet-apphost-pack-6.0
  dotnet-host dotnet-hostfxr-6.0 dotnet-runtime-6.0 dotnet-runtime-deps-6.0
  dotnet-sdk-6.0 dotnet-targeting-pack-6.0 netstandard-targeting-pack-2.1
The following NEW packages will be installed:
  aspnetcore-runtime-6.0 aspnetcore-targeting-pack-6.0 dotnet-apphost-pack-6.0
  dotnet-host dotnet-hostfxr-6.0 dotnet-runtime-6.0 dotnet-runtime-deps-6.0
  dotnet-sdk-6.0 dotnet-targeting-pack-6.0 dotnet6
0 upgraded, 11 newly installed, 0 to remove and 77 not upgraded.
Need to get 125 MB of archives.
After this operation, 508 MB of additional disk space will be used.
Get:1 jammy/main amd64 dotnet-host amd64 7.0.0-1 [57.3 kB]
Get:2 jammy/main amd64 dotnet-hostfxr-6.0 amd64 6.0.11-1 [142 kB]
Get:3 jammy/main amd64 dotnet-runtime-deps-6.0 amd64 6.0.11-1 [2802 B]
Get:4 jammy/main amd64 dotnet-runtime-6.0 amd64 6.0.11-1 [22.8 MB]
Get:5 jammy-updates/universe amd64 dotnet6 amd64 6.0.110-0ubuntu1~22.04.1 [20.5 kB]
Get:6 jammy/main amd64 aspnetcore-runtime-6.0 amd64 6.0.11-1 [6608 kB]
Get:7 jammy/main amd64 dotnet-targeting-pack-6.0 amd64 6.0.11-1 [2134 kB]
Get:8 jammy/main amd64 aspnetcore-targeting-pack-6.0 amd64 6.0.11-1 [1316 kB]
Get:9 jammy/main amd64 dotnet-apphost-pack-6.0 amd64 6.0.11-1 [3524 kB]
Get:10 jammy/main amd64 netstandard-targeting-pack-2.1 amd64 2.1.0-1 [1476 kB]
Get:11 jammy/main amd64 dotnet-sdk-6.0 amd64 6.0.403-1 [86.6 MB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 125 MB in 2s (82.5 MB/s)
Selecting previously unselected package dotnet-host.
(Reading database ... 
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 20287 files and directories currently installed.)
Preparing to unpack .../00-dotnet-host_7.0.0-1_amd64.deb ...
Unpacking dotnet-host (7.0.0-1) ...
Selecting previously unselected package dotnet-hostfxr-6.0.
Preparing to unpack .../01-dotnet-hostfxr-6.0_6.0.11-1_amd64.deb ...
Unpacking dotnet-hostfxr-6.0 (6.0.11-1) ...
Selecting previously unselected package dotnet-runtime-deps-6.0.
Preparing to unpack .../02-dotnet-runtime-deps-6.0_6.0.11-1_amd64.deb ...
Unpacking dotnet-runtime-deps-6.0 (6.0.11-1) ...
Selecting previously unselected package dotnet-runtime-6.0.
Preparing to unpack .../03-dotnet-runtime-6.0_6.0.11-1_amd64.deb ...
Unpacking dotnet-runtime-6.0 (6.0.11-1) ...
Selecting previously unselected package aspnetcore-runtime-6.0.
Preparing to unpack .../04-aspnetcore-runtime-6.0_6.0.11-1_amd64.deb ...
Unpacking aspnetcore-runtime-6.0 (6.0.11-1) ...
Selecting previously unselected package dotnet-targeting-pack-6.0.
Preparing to unpack .../05-dotnet-targeting-pack-6.0_6.0.11-1_amd64.deb ...
Unpacking dotnet-targeting-pack-6.0 (6.0.11-1) ...
Selecting previously unselected package aspnetcore-targeting-pack-6.0.
Preparing to unpack .../06-aspnetcore-targeting-pack-6.0_6.0.11-1_amd64.deb ...
Unpacking aspnetcore-targeting-pack-6.0 (6.0.11-1) ...
Selecting previously unselected package dotnet-apphost-pack-6.0.
Preparing to unpack .../07-dotnet-apphost-pack-6.0_6.0.11-1_amd64.deb ...
Unpacking dotnet-apphost-pack-6.0 (6.0.11-1) ...
Selecting previously unselected package netstandard-targeting-pack-2.1.
Preparing to unpack .../08-netstandard-targeting-pack-2.1_2.1.0-1_amd64.deb ...
Unpacking netstandard-targeting-pack-2.1 (2.1.0-1) ...
Selecting previously unselected package dotnet-sdk-6.0.
Preparing to unpack .../09-dotnet-sdk-6.0_6.0.403-1_amd64.deb ...
Unpacking dotnet-sdk-6.0 (6.0.403-1) ...
Selecting previously unselected package dotnet6.
Preparing to unpack .../10-dotnet6_6.0.110-0ubuntu1~22.04.1_amd64.deb ...
Unpacking dotnet6 (6.0.110-0ubuntu1~22.04.1) ...
Setting up dotnet-host (7.0.0-1) ...
Setting up dotnet-apphost-pack-6.0 (6.0.11-1) ...
Setting up netstandard-targeting-pack-2.1 (2.1.0-1) ...
Setting up dotnet-targeting-pack-6.0 (6.0.11-1) ...
Setting up dotnet-runtime-deps-6.0 (6.0.11-1) ...
Setting up aspnetcore-targeting-pack-6.0 (6.0.11-1) ...
Setting up dotnet-hostfxr-6.0 (6.0.11-1) ...
Setting up dotnet-runtime-6.0 (6.0.11-1) ...
Setting up aspnetcore-runtime-6.0 (6.0.11-1) ...
Setting up dotnet-sdk-6.0 (6.0.403-1) ...

It would appear that something between .NET 6.0.9 and 6.0.11 is causing this Regular expression to no longer match.

My hypotheses at the moment for the cause of the issue are:

  • A bug in .NET 6.010 or 6.0.11 that affects the Regex in the scanner code.
  • The tool is rolling forward to .NET 7 at runtime if present, and then that version contains a behavioural change and/or bug that affects the Regex in the scanner code.

Hi @Martin_Costello,

Is this happening only under linux?

I’ve tried to isolate the problem and reproduce it on windows without any luck. You can find the source code here:

This simulate the usage from the scanner. One library is compiled for net46;netstandard2.0 and the tool that is using it is compiled to target netcoreapp2.1;netcoreapp3.1;net46;net5.0.

I’ve also added a global.json with "rollForward": "latestMajor".

If I run this dotnet .\ReproRegex.dll 27bafbfeabc175b5b4bf6062544cb9de99259a87 for all target frameworks, it works as expected.

*the token was generated only for this purpose, it’s valid but not used in dev or production

We’ve only been able to reproduce this in our GitHub Actions environment, where all of the agents use Linux.

We managed to narrow down the issue to being precipitated by PowerShell 7.3 coming with .NET 7. Rolling back to 7.2 on the runner image resolves the issue with the tool, so I think it’s some sort of incompatibility between the code being compiled for .NET 5 but rolling forward to run with .NET 7.