AD0001 when switching from Debug to Release

Window 10 22H2
Visual Studio 2019 V16.11.27
sonarlint 6.16.0.69538
VB.net

When switching from Debug to Release mode I get 915 “AD0001” warnings. Restarting Visual Studio resolves the issue.

All warnings are similar to this:

Severity	Code	Description	Project	File	Line	Source
Warning	AD0001	Analyzer 'SonarAnalyzer.Rules.VisualBasic.SymbolicExecutionRunner' 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: PropixFL
SyntaxTree: C:\Development\IPDS and Propix\PropixFL\PropixFL\clsEHs.vb
SyntaxNode: Public Function Count() As Integer ... [MethodBlockSyntax]@[1853..1938) (70,4)-(74,16)

System.NullReferenceException: Object reference not set to an instance of an object.
   at lambda_method(Closure , Object , SyntaxTree , String , CancellationToken , ReportDiagnostic& )
   at StyleCop.Analyzers.Lightup.SyntaxTreeOptionsProviderWrapper.TryGetDiagnosticValue(SyntaxTree tree, String diagnosticId, CancellationToken cancellationToken, ReportDiagnostic& severity)
   at SonarAnalyzer.Rules.SymbolicExecutionRunnerBase.IsEnabled(SonarSyntaxNodeReportingContext context, DiagnosticDescriptor descriptor)
   at SonarAnalyzer.Rules.SymbolicExecutionRunnerBase.<>c__DisplayClass17_0.<AnalyzeRoslyn>b__0(KeyValuePair`2 x)
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.GroupedEnumerable`3.GetEnumerator()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at SonarAnalyzer.Rules.SymbolicExecutionRunnerBase.AnalyzeRoslyn(SonarAnalysisContext analysisContext, SonarSyntaxNodeReportingContext nodeContext, SyntaxNode body, ISymbol symbol)
   at SonarAnalyzer.Rules.SymbolicExecutionRunnerBase.Analyze(SonarAnalysisContext analysisContext, SonarSyntaxNodeReportingContext nodeContext, SyntaxNode body, ISymbol symbol)
   at SonarAnalyzer.Rules.SymbolicExecutionRunnerBase.Analyze[TNode](SonarAnalysisContext analysisContext, SonarSyntaxNodeReportingContext context, Func`2 getBody)
   at SonarAnalyzer.Rules.VisualBasic.SymbolicExecutionRunner.<>c__DisplayClass4_0.<Initialize>b__0(SonarSyntaxNodeReportingContext c)
   at SonarAnalyzer.AnalysisContext.SonarAnalysisContext.Execute[TSonarContext,TRoslynContext](TSonarContext context, Action`1 action, SyntaxTree sourceTree, GeneratedCodeRecognizer generatedCodeRecognizer)
   at SonarAnalyzer.AnalysisContext.SonarAnalysisContext.<>c__DisplayClass23_0`1.<RegisterNodeAction>b__0(SyntaxNodeAnalysisContext c)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__62`1.<ExecuteSyntaxNodeAction>b__62_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----

Suppress the following diagnostics to disable this analyzer: S2222, S2259, S3655, S3900	PropixFL		1	IntelliSense

This is constant issue with several different applications. Tried removing and re-installing SonarLink but issue still exist. The issue also occurs when switching from Debug to Release. Any thoughts on how to fix this?

Hi @David_Hitchner does the problem still occur if you reference the Sonar VB.NET analyzers as a NuGet package? i.e.

  1. uninstall SonarLint
  2. add a NuGet package reference to SonarAnalyzer.VisualBasic?

Thanks.

Duncan,
Yes. The problem still occurs when installed as a NuGet package. In one project it added 403 “AD0001” warnings.

Regards,
David Hitchner

Thanks for checking @David_Hitchner. I’ve asked the Languages team who wrote the analysis rule to take a look as the issue doesn’t seem to be related to SonarLint per se.

1 Like

Hello @David_Hitchner,
Some questions:

  • Do you see AD0001s only when turning from Debug to Release mode? Otherwise, there’s no AD0001 in the logs?
  • Would it be possible to share this file
    SyntaxTree: C:\Development\IPDS and Propix\PropixFL\PropixFL\clsEHs.vb?

Thanks a lot!

1 Like

Mary, Sorry, I cannot share the file but I can tell you that “AD0001” errors show for all files in the project as well as in other projects. So far I have not been able to tie it down to any specific file or cause. I can also say that the problem does not appear in Visual Studio 2022 on the same system. I could resolve the issue by using 2022 but because it is 64-bit I need to replace some of the controls in some of the projects before that can happen.

Hello @David_Hitchner.

Do you have maybe different configuration files for analysis between debug and release modes (such files are editorconfig, global configuration files, or ruleset files)?

Mary,
Thanks for your suggestions. I had hoped that this provided a solution because I did have different rulesets for debug and release. Changing the ruleset does trigger the issue. I changed debug and release to use the same ruleset “Microsoft Managed Recommended Rules”. I then exited Visual Studio and re-opened the application. Going from debug to release or release to debug still causes the AD0001 warnings.

Hi @David_Hitchner,
Is it possible to share with me the ruleset files, so I can try to reproduce the issue?
Thanks!

Ruleset.zip (810 Bytes)
Here is the ruleset. It’s just the standard one supplied with Visual Studio

Just to make sure I understood properly, from your side this is the only extra ruleset that you provide?
From what I understood from a previous post you mentioned that you use different rulesets for debug and release modes.
Would it be possible to provide me with these (unless I understood wrong)?

Could you also tell me how you pass the rulesets to your projects?

thanks!

The ruleset is set in the project properties. I have included an image along with
my custom ruleset.
CustomRuleset.zip (77.7 KB)

Hello @David_Hitchner ,

I apologize for the late reply.
Unfortunately, I still cannot reproduce the issue.

I’m working with VS 2019 16.11, a VB.NET project targeting NET5, providing at project level the rulesets (the ones you provided) and changing them between Release and Debug. Behavior is so far as expected.

Could you please tell me which framework you are targeting in your project?
Is it possible that you have customized the project build somehow?

Would you be willing to build your project with a more recent MSBuild/VS version (VS22, for example) to see if you have the same issue?

Thank you.

1 Like

Mary, The issue does not occur in VS 2022. I am still using VS 2019 for some projects because of 32-bit controls.

Thank you for testing this and for your patience.

Could you please tell me if there’s something different in your project from the setup I described in my previous message?

  • which framework do you target?
  • do you maybe have altered the build somehow? With targets for example?

One more note: I noticed that you mentioned Visual Studio 2019 V16.11.27.
Could you try updating to the latest patch 16.11.30?

I noticed that I tested with 16.11.29 - so this might do the trick.
It has happened in the past that there was a bug for a certain MSBuild version and it got resolved in a patch later.

Thank you very much!

Mary, I am running Visual Studio 2019 Version 16.11.30 and targeting .NET Framework 4.6.2. I have another solution that has the same issue and it targets .NET Framework 4.5.2.
The first solution targeting 4.6.2 does not experience the issue in Visual Studio 2022. I am unable to try the second solution due to the use of 32-bit controls.

@David_Hitchner a couple more questions:

  1. are your MSBuild projects SDK-style or in the legacy format (or both)?

  2. how is background analysis configured in your IDE? i.e.

It might be worth checking the “Enable file logging for file diagnostics” option to see if the log gives any hints about what is happening.

Thanks.