Dotnet-sonarscanner fails to access to server

Hi all,
I’m running a dotnet-sonarscanner within an organisation gitlab instance to access sonarqube instance (which runs on an organisation machine.)

From gitlab pipeline I can see the SonarQube machine:
curl http://MY-SONAR-QUBE-Instance
but can not access /api/server/version when I run the following, it fails (timeout).
curl http://MY-SONAR-QUBE-Instance/api/server/version

Even running the scanner, fails:
dotnet sonarscanner begin /d:sonar.host.url="$SONARQUBE_URL" /d:sonar.verbose=true /k:"$SONARQUBE_PROJECT_KEY" /d:sonar.login=“SONARQUBE_AUTH_TOKEN”

09:00:11.993  Failed to request and parse 'http://MY-SONAR-QUBE-Instance/api/server/version': The operation was canceled.
Unhandled exception. System.Threading.Tasks.TaskCanceledException: The operation was canceled.
 ---> System.IO.IOException: Unable to read data from the transport connection: Operation canceled.
 ---> System.Net.Sockets.SocketException (125): Operation canceled
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
   at System.Net.Http.HttpConnection.FillAsync()
   at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean foldedHeadersAllowed)
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at SonarScanner.MSBuild.PreProcessor.WebClientDownloader.Download(String url, Boolean logPermissionDenied)
   at SonarScanner.MSBuild.PreProcessor.SonarWebService.<>c__DisplayClass18_0.<<DownloadServerVersion>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at SonarScanner.MSBuild.PreProcessor.SonarWebService.DoLogExceptions[T](Func`1 op, String url)
   at SonarScanner.MSBuild.PreProcessor.SonarWebService.DownloadServerVersion()
   at SonarScanner.MSBuild.PreProcessor.SonarWebService.GetServerVersion()
   at SonarScanner.MSBuild.PreProcessor.SonarWebService.WarnIfSonarQubeVersionIsDeprecated()
   at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.DoExecute(ProcessedArgs localSettings)
   at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.Execute(String[] args)
   at SonarScanner.MSBuild.BootstrapperClass.PreProcess()
   at SonarScanner.MSBuild.BootstrapperClass.Execute()
   at SonarScanner.MSBuild.Program.Execute(String[] args, ILogger logger)
   at SonarScanner.MSBuild.Program.Execute(String[] args)
   at SonarScanner.MSBuild.Program.Main(String[] args)
   at SonarScanner.MSBuild.Program.<Main>(String[] args)

SonarQube version is 7.7.0.23042

Any ideas why we get this error? How can we resolve it?

regards,
Soheil

Please I have a similar problem, with the command:

dotnet sonarscanner begin /k:“newproct” /d:sonar.host.url=“http://mysonarserver:9000” /d:sonar.login=“token”

with the following message:

Failed to request and parse ‘http: // mysonarserver: 9000 / api / server / version’: Object reference not set to an instance of an object.
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at SonarScanner.MSBuild.PreProcessor.SonarWebService. <> c__DisplayClass18_0. < b__0> d.MoveNext ()
— End of stack trace from previous location —
at SonarScanner.MSBuild.PreProcessor.SonarWebService.DoLogExceptions [T] (Func`1 op, String url)
at SonarScanner.MSBuild.PreProcessor.SonarWebService.DownloadServerVersion ()
at SonarScanner.MSBuild.PreProcessor.SonarWebService.GetServerVersion ()
at SonarScanner.MSBuild.PreProcessor.SonarWebService.WarnIfSonarQubeVersionIsDeprecated ()
at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.DoExecute (ProcessedArgs localSettings)
at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.Execute (String args)
at SonarScanner.MSBuild.BootstrapperClass.PreProcess ()
at SonarScanner.MSBuild.BootstrapperClass.Execute ()
at SonarScanner.MSBuild.Program.Execute (String args, ILogger logger)
at SonarScanner.MSBuild.Program.Execute (String args)
at SonarScanner.MSBuild.Program.Main (String args)
at SonarScanner.MSBuild.Program. (String args)

I have the Sonarqube server 8.8.0
using visual code on linux

Hi @soheils and welcome to the community.

Maybe you want to fix this before going further ? Please note also that your version of SonarQube is not supported anymore. A good move would be to update to the 7.9 LTS (which will be replaced in the coming days by the new LTS (8.9).

Hi @rolandomf1

Can you try to ping this URL from a IWR or IRM powershell command to this is this is scanner related or not ?

Thanks.

I can’t get there with ping, I didn’t realize that.

now if I arrive with ping, but the same problem continues.

What did you do to be able to ping that URL ?

Thanks for your reply.
As it’s on the corporate network running in a Docker, the IT team will upgrade it but not clear when it will happen.

I’m wondering if there is any settings that need to be applied on SonarQube , as the server URL is accessible by curl command but SonarQube API is not accessible.
Can this be an issue is CORS setting in SonarQube? I read a post about setting Access-Control-Allow-Origin: * on SonarQube server in
https://community.sonarsource.com/t/facing-cors-policy-issue-when-calling-the-sonarqube-apis-using-http-in-angularjs/6361

Not sure if it can help, but where should I set this in SonarQube server?

Hi, API calls from the scanner are not sensitive to CORS policy. Now that you fixed the ping issue you had, what is the error you have on the scanner side?

the same problem keeps appearing, the following message appears:
dotnet sonarscanner begin -d:sonar.login=key_sonar -k:net -d:sonar.host.url=http://serversonar:9000 SonarScanner for MSBuild 5.2.1 Using the .NET Core version of the Scanner for MSBuild Pre-processing started. Preparing working directories… 08:37:34.966 Updating build integration targets… 08:37:35.046 Failed to request and parse ‘http://serversonar:9000/api/server/version’: Object reference not set to an instance of an object. Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at SonarScanner.MSBuild.PreProcessor.SonarWebService.<>c__DisplayClass18_0.<b__0>d.MoveNext() — End of stack trace from previous location — at SonarScanner.MSBuild.PreProcessor.SonarWebService.DoLogExceptions[T](Func1 op, String url) at SonarScanner.MSBuild.PreProcessor.SonarWebService.DownloadServerVersion() at SonarScanner.MSBuild.PreProcessor.SonarWebService.GetServerVersion() at SonarScanner.MSBuild.PreProcessor.SonarWebService.WarnIfSonarQubeVersionIsDeprecated() at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.DoExecute(ProcessedArgs localSettings) at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.Execute(String[] args) at SonarScanner.MSBuild.BootstrapperClass.PreProcess() at SonarScanner.MSBuild.BootstrapperClass.Execute() at SonarScanner.MSBuild.Program.Execute(String[] args, ILogger logger) at SonarScanner.MSBuild.Program.Execute(String[] args) at SonarScanner.MSBuild.Program.Main(String[] args) at SonarScanner.MSBuild.Program.<Main>(String[] args) Cleaning up file based variables 00:00 ERROR: Job failed: exit status 1

Hi, guys.

I am working with 8.9 LTS version and facing the same problem.
The GITLAB Pipeline is running sonar-scanner command at windows server.
The message error is Failed to request and parse ‘http://xxxxxxxx:9000/api/server/version’: Object reference not set to an instance of an object.

The problem is that I access this server and type this URL at browser and it returns the Sonarqube version “8.9.0.43852”. There isn’t firewall or proxy between the servers.

Hello everyone,

Facing the same issue with SonarScanner.MsBuild.exe (I’ve tried with version 5.2.1 and 5.2.0)
The Sonarqube is a docker image (tag: lts-community)

I’ve opened the URL (http://localhost:9000/api/server/version) in a browser and same as @alevenelli I’ve the version number displayed in plain text.

This topic was automatically closed after 3 days. New replies are no longer allowed.