SonarCloud Coverage,Azure Devops SqlException Failed to initialize the Common Language Runtime (CLR)

Environment is Azure Devops Pipeline, running Code Coverage analysis of C# Unit Tests, accessing SQL Server via NHibernate, on Azure Devops Agent:

  • SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
  • VSBuild@1
  • VSTest@2

Result and Problem

  1. Running Pipeline with VSTest@2 Unit Tests works fine, 100% successful without SonarCloud.
  2. Wrapping the SonarSource.Sonarcloud task around the build and tests, immediately causes errors on every test which uses System.Data.SqlClient.SqlDataReader.Read() via NHibernate code as soon as it attempts to access SQL via connections string. Error is:
System.Data.SqlClient.SqlException : Failed to initialize the Common Language Runtime (CLR) v4.0.30319 with HRESULT 0x80004005. You need to restart SQL Server to use CLR integration features.
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
    at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
    at System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
    at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
    at System.Data.SqlClient.SqlDataReader.Read()
    at System.Data.SqlClient.SqlMetaDataFactory.addUDTsToDataTypesTable(DataTable dataTypesTable, SqlConnection connection, String ServerVersion)
    at System.Data.SqlClient.SqlMetaDataFactory.GetDataTypesTable(SqlConnection connection)
    at System.Data.SqlClient.SqlMetaDataFactory.PrepareCollection(String collectionName, String[] restrictions, DbConnection connection)
    at System.Data.ProviderBase.DbMetaDataFactory.GetSchema(DbConnection connection, String collectionName, String[] restrictions)
    at System.Data.SqlClient.SqlConnection.GetSchema(String collectionName, String[] restrictionValues)
    at NHibernate.Dialect.Schema.AbstractDataBaseSchema.GetReservedWords()
    at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
    at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.UpdateDialectKeywords(Dialect dialect, IConnectionHelper connectionHelper)
    at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
    at NHibernate.Cfg.Configuration.BuildSessionFactory()

  • ALM used - Azure DevOps
  • CI system used - Azure DevOps
  • Languages of the repository - C#

Hey there.

It would be helpful if you could share verbose logs from the scanner / build / test processes.

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        # Applies to SonarQubePrepare as well
        - task: SonarCloudPrepare@1
              SonarCloud: 'sonarcloud'
              organization: 'zucchinibreadco'
              scannerMode: 'MSBuild'
              projectKey: 'zuchhinibreadco_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d


dotnet build -v:d
dotnet test -v:d

I can also start a private message for you to share them if needed.