Problem with UserAgent HTTP header in dotnet sonarscanner

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    Release 5.8.0 · SonarSource/sonar-scanner-msbuild · GitHub)

  • what are you trying to achieve
    run the dotnet sonarscanner command

  • what have you tried so far to achieve this
    The command fails with
    08:19:35.079 Downloading from…
    08:19:35.738 Failed to request and parse ‘’: Object reference not set to an instance of an object.

From stepping through the sonarqube code (specifically SonarScanner.MSBuild.PreProcessor WebClientDownloader), the above error is due to a 403 error because at my company there is a firewall rule (AWS WAF) to check that “User-Agent” is set in the HTTP header.

However the code in v5.8.0. has this line (which sets header as “UserAgent” instead of “User-Agent”) so the firewall blocks the traffic.

client.DefaultRequestHeaders.Add(HttpRequestHeader.UserAgent.ToString(), $"ScannerMSBuild/{Utilities.ScannerVersion}");

but should probably be something like this instead so User-Agent is set.

        var productValue = new ProductInfoHeaderValue("ScannerMSBuild", $"{Utilities.ScannerVersion}");


Hi Joe,

Welcome to the community!

What’s your SonarQube version? You can find it in the page footer.


Hi Ann
My version is

  • Developer Edition
  • Version 9.2.4 (build 50792)

Although I get the error before I get to uploading the results of the scan i.e. the error is when I run the command

dotnet sonarscanner begin /k:“ivzdso_myprojectname” /d:“sonar.login=50…e70b3e” /d:“” /d:“sonar.verbose=true”


Thanks for your version and edition. There are calls back and forth to the server in the begin step, so version could matter, but I’m not finding anything in Jira to indicate we’ve worked on this. I’ve pinged the team. Hopefully they’ll be along soon.


Hi @xetle,

Thanks a lot for your feedback. I can confirm the problem and I think your investigation is spot on :slight_smile:

I have created the following issue on our side: User-Agent header is not correctly set · Issue #1350 · SonarSource/sonar-scanner-msbuild · GitHub

1 Like