Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSC Error AD0001 CSharpDiagnosticAnalyzerApiUsageAnalyzer NullReferenceException #2961

Closed
MattOG opened this issue Oct 21, 2019 · 6 comments
Closed

Comments

@MattOG
Copy link

MattOG commented Oct 21, 2019

Started getting this error after updating my solution to target .NetCore 3.0.

Attempted to use the (downgraded) version of 2.9.6-beta1.19502.2 as suggested here: #2889 (just in case) but as expected the error didn't go away.

It happens in 4 of the projects in the solution, each with a different entry under the ISymbol tag below.

Analyzer package

Microsoft.CodeAnalysis.FxCopAnalyzers

Package Version

v2.9.6 (Latest)

Diagnostic ID

AD0001 Analyzer 'Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticAnalyzerApiUsageAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.

Analyzer 'Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticAnalyzerApiUsageAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: ProNET.Web
ISymbol: Startup (NamedType)

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticAnalyzerApiUsageAnalyzer`1.AddUsedNamedTypeCore(ITypeSymbol typeOpt, Builder builder, Boolean& hasAccessToTypeFromWorkspaceAssemblies)
   at Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticAnalyzerApiUsageAnalyzer`1.AddUsedNamedTypeCore(ITypeSymbol typeOpt, Builder builder, Boolean& hasAccessToTypeFromWorkspaceAssemblies)
   at Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticAnalyzerApiUsageAnalyzer`1.GetUsedNamedTypes(INamedTypeSymbol namedType, Compilation compilation, CancellationToken cancellationToken, Boolean& hasAccessToTypeFromWorkspaceAssemblies)
   at Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticAnalyzerApiUsageAnalyzer`1.<>c__DisplayClass11_0.<Initialize>b__1(SymbolAnalysisContext symbolContext)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteSymbolActionsCore>b__43_1(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
'.

Repro steps

  1. Updated project files.
  2. Install NuGet packages.
  3. Run analysis.

Expected behavior

Not an AD0001 error

Actual behavior

An AD001 error

@MattOG MattOG changed the title CSC Error AD0001 Analyzer 'Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticAnalyzerApiUsageAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. CSC Error AD0001 CSharpDiagnosticAnalyzerApiUsageAnalyzer threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. Oct 21, 2019
@MattOG MattOG changed the title CSC Error AD0001 CSharpDiagnosticAnalyzerApiUsageAnalyzer threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. CSC Error AD0001 CSharpDiagnosticAnalyzerApiUsageAnalyzer NullReferenceException Oct 21, 2019
@pleonex
Copy link

pleonex commented Oct 23, 2019

It's happening for us in .NET Framework 4.7.2 projects too.

@mavasani
Copy link
Member

Can you try to add a package reference to the latest stable version of https://www.nuget.org/packages/Microsoft.CodeAnalysis.Analyzers/?

@MattOG
Copy link
Author

MattOG commented Oct 23, 2019

@mavasani I have the latest version installed as detailed in the opening post. Unless 2.9.6 (which your link points to) isn't the latest?

@mavasani
Copy link
Member

@MattOG Your description mentions you have installed 2.9.6 version of Microsoft.CodeAnalysis.FxCopAnalyzers, but that package does not contain the ApiUsageAnalyzer. Did you also install latest version of Microsoft.CodeAnalysis.Analyzers, which contains this analyzer?

@MattOG
Copy link
Author

MattOG commented Oct 23, 2019

@mavasani Apologies, my ability to read seems to have gone astray.

I'm applying your suggestion now.

Thanks.

@MattOG
Copy link
Author

MattOG commented Oct 23, 2019

@mavasani This has solved this issue.
Thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants