Consider the following code:
var d = new Dictionary<IMethodSymbol, int>(SymbolEqualityComparer.Default);
Compiling this results in:
Analyzer 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.CompareSymbolsCorrectlyAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'De objectverwijzing is niet op een exemplaar van een object ingesteld.'.
Exception occurred with following context:
Compilation: [...]
IOperation: ObjectCreation
SyntaxTree: [...]
SyntaxNode: [...]
System.NullReferenceException: De objectverwijzing is niet op een exemplaar van een object ingesteld.
at Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.CompareSymbolsCorrectlyAnalyzer.<>c__DisplayClass15_0.<HandleObjectCreation>b__0(IArgumentOperation arg)
at System.Linq.ImmutableArrayExtensions.Any[T](ImmutableArray`1 immutableArray, Func`2 predicate)
at Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.CompareSymbolsCorrectlyAnalyzer.HandleObjectCreation(OperationAnalysisContext& context, INamedTypeSymbol symbolType, INamedTypeSymbol symbolEqualityComparerType, ImmutableHashSet`1 collectionTypes)
at Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.CompareSymbolsCorrectlyAnalyzer.<>c__DisplayClass12_1.<Initialize>b__3(OperationAnalysisContext context)
Seeing the exact same error.
Seeing the same with HashSet<ITypeSymbol>. The only way to get around this is to suppress the issue in code for now. :(
Seems to relate to #4470 and #4568, issues have been fixed and I have just tested on master, there is no longer any issue.
I am closing the issue, if you are still affected, could you please ping us and ideally provide some reproducer and the version of the analyzer you are using?!
Most helpful comment
Seeing the same with
HashSet<ITypeSymbol>. The only way to get around this is to suppress the issue in code for now. :(