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

IdentifiersShouldHaveCorrectSuffixAnalyzer AD0001 #3414

Closed
Evangelink opened this issue Mar 23, 2020 · 8 comments · Fixed by #3424
Closed

IdentifiersShouldHaveCorrectSuffixAnalyzer AD0001 #3414

Evangelink opened this issue Mar 23, 2020 · 8 comments · Fixed by #3424

Comments

@Evangelink
Copy link
Member

Analyzer package

Microsoft.CodeAnalysis.FxCopAnalyzers

Package Version

3.0.0-beta2.20170.4

Issue

Error	AD0001	Analyzer 'Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.IdentifiersShouldHaveCorrectSuffixAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.

I don't have any stacktrace in my IDE, is there any option somewhere I can switch?

@mavasani
Copy link
Contributor

Hmm how did you encounter this? Was it from build or live analysis? Expanding the IDE live analysis diagnostic in error list should always give you a callstack and richer exception information

@mavasani
Copy link
Contributor

Wondering if the issue here is that BaseType can be null:

var baseTypes = excludeIndirectBaseTypes
? (new[] { namedTypeSymbol.BaseType })
: namedTypeSymbol.GetBaseTypes();

https://github.com/dotnet/roslyn/blob/d2e50fd781d236530fbfc3ff29c24f99fedbe755/src/Compilers/Core/Portable/Symbols/ITypeSymbol.cs#L29-L34

        /// <summary>
        /// The declared base type of this type, or null. The object type, interface types,
        /// and pointer types do not have a base type. The base type of a type parameter
        /// is its effective base class.
        /// </summary>
        INamedTypeSymbol? BaseType { get; }

@Evangelink
Copy link
Member Author

Hmm how did you encounter this? Was it from build or live analysis? Expanding the IDE live analysis diagnostic in error list should always give you a callstack and richer exception information

I am using the last pre-release nuget package. And I don't have any expand option which is why I was asking.

image

Regarding the location you are pointing to, yeah that seems like a bug.

@mavasani
Copy link
Contributor

Tag @sharwell - seems like this is an AD0001 from command line build. Support to have context information was added in dotnet/roslyn#35871, but likely MSBuild output filters out extra info?

@mavasani
Copy link
Contributor

Switching to MSBuild build output verbosity to detailed shows the exception information:

1>    CSC : warning AD0001: Analyzer 'Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.IdentifiersShouldHaveCorrectSuffixAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
1>    Exception occurred with following context:
1>    Compilation: Microsoft.CodeAnalysis.AnalyzerUtilities
1>    ISymbol: IDataFlowAnalysisResult (NamedType)
1>    System.NullReferenceException: Object reference not set to an instance of an object.
1>    at Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.IdentifiersShouldHaveCorrectSuffixAnalyzer.TryGetTypeSuffix(IEnumerable`1 typeSymbols, ImmutableDictionary`2 hardcodedMap, SymbolNamesWithValueOption`1 userMap, SuffixInfo& suffixInfo)
1>    at Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.IdentifiersShouldHaveCorrectSuffixAnalyzer.<>c__DisplayClass11_0.<AnalyzeCompilationStart>b__0(SymbolAnalysisContext saContext)
1>    at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteSymbolActionsCore>b__48_1(ValueTuple`2 data)
1>    at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
1>    -----
1>    Suppress the following diagnostics to disable this analyzer: CA1710

@mavasani
Copy link
Contributor

This NRE seems to be occur very commonly on just released https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers/3.0.0-beta2.final. I will send out a fix and try to release a 3.0.0-beta3.final with a fix soon.

mavasani added a commit to mavasani/roslyn-analyzers that referenced this issue Mar 24, 2020
mavasani added a commit to mavasani/roslyn-analyzers that referenced this issue Mar 24, 2020
@Evangelink
Copy link
Member Author

Thank you for the fix and sorry to have miss this case when doing the implementation.

@mavasani
Copy link
Contributor

No worries @Evangelink! Thanks for your 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

Successfully merging a pull request may close this issue.

2 participants