Number in appsettings.json causes SonarScanner to throw OverflowException during build

Versions Used

  • SonarScanner for MSBuild 5.14
  • SonarQube 9.9.1 (build 69595)

Getting the following error

An exception is thrown by the SonarScanner when building a net6.0 web project in Azure DevOps and when scanning/building locally using the .NET Global Tool:

##[error]CSC(0,0): Error AD0001: Analyzer 'SonarAnalyzer.Rules.CSharp.DoNotHardcodeCredentials' threw an exception of type 'System.OverflowException' with message 'Value was either too large or too small for an Int32.'.
##[debug]Processed: ##vso[task.logissue type=Error;sourcepath=CSC;linenumber=0;columnnumber=0;code=AD0001;]Analyzer 'SonarAnalyzer.Rules.CSharp.DoNotHardcodeCredentials' threw an exception of type 'System.OverflowException' with message 'Value was either too large or too small for an Int32.'.
CSC : error AD0001: Analyzer 'SonarAnalyzer.Rules.CSharp.DoNotHardcodeCredentials' threw an exception of type 'System.OverflowException' with message 'Value was either too large or too small for an Int32.'. [D:\Agent\2\_work\2112\s\MyProject\MyProject.csproj]
  CompilerServer: server - server processed compilation - 4bc4d9af-cb04-4c90-9beb-f54e1b7af52b

Findings

After a bit of digging around, I found that this error was caused by a value in the appsettings.json file where the number is larger than the maximum int32 value

{
  "largeNum": 2147483648 //Throws OverflowException
  "anotherNum": 2147483647 //Does not throw an exception
}

Thanks,

Jonathan

1 Like

Hello @shnitze,

Thanks a lot for reporting this and also thanks for going deeper to find the root cause.
I’ve opened a github issue for this bug that you can follow here.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.