Exceptions in Visual Studio 2022

Please provide

  • Operating system: Windows 10
  • Visual Studio version: 17.12.3
  • SonarLint plugin version: 8.9.0.11507
  • Programming language you’re coding in: c#
  • Is connected mode used:No
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:

I got some analyzer exceptions when I had some invalid c# code, this was the offending code (new ASP.NET Core 9 Aspire project with space in the projectname. That seems not to be supported that well.)



var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.Data Protection Demo>("data protection demo");

builder.AddProject<Projects.Data Protection Demo2>("data protection demo2");

builder.Build().Run();


Severity	Code	Description	Project	File	Line	Suppression State	Details
Warning (active)	AD0001	Analyzer 'SonarAnalyzer.Rules.CSharp.UseCharOverloadOfStringMethods' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
Exception occurred with following context:
Compilation: Data Protection Demo2

System.NullReferenceException: Object reference not set to an instance of an object.
   at SonarAnalyzer.Rules.UseCharOverloadOfStringMethodsBase`2.CompilationTargetsValidNetVersion(Compilation compilation)
   at SonarAnalyzer.Rules.UseCharOverloadOfStringMethodsBase`2.<Initialize>b__5_0(SonarCompilationStartAnalysisContext start)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
-----

Suppress the following diagnostics to disable this analyzer: S6610	Z:\GitHubTN\Talks\Conference Talks\Swetugg 2025\Demo - Data Protection\Data Protection Demo\Data Protection Demo2\Data Protection Demo2.csproj ({4C50C5D3-C4BD-4637-869C-0F15BFD81A27})	Z:\GitHubTN\Talks\Conference Talks\Swetugg 2025\Demo - Data Protection\Data Protection Demo\Data Protection Demo2\Data Protection Demo2.csproj	1		



Severity	Code	Description	Project	File	Line	Suppression State	Details
Warning (active)	AD0001	Analyzer 'SonarAnalyzer.Rules.CSharp.BooleanLiteralUnnecessary' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
Exception occurred with following context:
Compilation: Data Protection Demo2

System.NullReferenceException: Object reference not set to an instance of an object.
   at SonarAnalyzer.Rules.BooleanLiteralUnnecessaryBase`1.<Initialize>b__9_0(SonarCompilationStartAnalysisContext x)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
-----

Suppress the following diagnostics to disable this analyzer: S1125	Z:\GitHubTN\Talks\Conference Talks\Swetugg 2025\Demo - Data Protection\Data Protection Demo\Data Protection Demo2\Data Protection Demo2.csproj ({4C50C5D3-C4BD-4637-869C-0F15BFD81A27})	Z:\GitHubTN\Talks\Conference Talks\Swetugg 2025\Demo - Data Protection\Data Protection Demo\Data Protection Demo2\Data Protection Demo2.csproj	1		




Severity	Code	Description	Project	File	Line	Suppression State	Details
Warning (active)	AD0001	Analyzer 'SonarAnalyzer.Rules.CSharp.UseUnixEpoch' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
Exception occurred with following context:
Compilation: Data Protection Demo2

System.NullReferenceException: Object reference not set to an instance of an object.
   at SonarAnalyzer.Rules.UseUnixEpochBase`3.IsUnixEpochSupported(Compilation compilation)
   at SonarAnalyzer.Rules.UseUnixEpochBase`3.<Initialize>b__10_0(SonarCompilationStartAnalysisContext c)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
-----

Suppress the following diagnostics to disable this analyzer: S6588	Z:\GitHubTN\Talks\Conference Talks\Swetugg 2025\Demo - Data Protection\Data Protection Demo\Data Protection Demo2\Data Protection Demo2.csproj ({4C50C5D3-C4BD-4637-869C-0F15BFD81A27})	Z:\GitHubTN\Talks\Conference Talks\Swetugg 2025\Demo - Data Protection\Data Protection Demo\Data Protection Demo2\Data Protection Demo2.csproj	1

Hello @tn-dev and thank you for reporting this.

I cannot unfortunately reproduce it.

The code you provided is the only piece of code in the file?
Would be great if you could provide me with a full repro project or the full file.

Thanks a lot!

Hi

You can download a sample project from

https://www.dropbox.com/scl/fi/zp5vwa227zvoy2ezp7cea/Test-Web-Application-Sonar.zip?rlkey=of9whe9akx850ci4l1mjx9rua&dl=0

basically

I create

Both projects are enlisted in Aspire. I have not modified any of the projects.

Yes, the code does not compile, and I get the sonar exceptions.

Guess its triggerd by the invalid code here due to the space in the project names.

1 Like

Thanks @tn-dev !

Unfortunately for security reasons I cannot pick this project up from dropbox.
Could you please share it via github or I could send you a private message and you can attach it there.

Thanks!

Send a email and I will reply with the attachment file.

Tore

1 Like

Hello Tore,

the issues disappear once there’s no compilation error?

do you have any particular configuration in your environment - how you build the projects etc?