dotnet / platform-compat

Roslyn analyzer that finds usages of APIs that will throw PlatformNotSupportedException on certain platforms.
MIT License
278 stars 43 forks source link

AD0001 DeprecatedAnalyzer NullReferenceException #96

Closed nnpcYvIVl closed 6 years ago

nnpcYvIVl commented 6 years ago

This code causes the following NullReferenceException.

namespace platform_compatAD0001
{
    public class Test
    {
        public sealed class InnerTest
        {
            public bool Valid { get; set; } = false;
        }

        public bool Valid { get; }

        public Test(InnerTest innertest)
        {
            Valid = innertest.Valid;
        }
    }
}
Warning AD0001  Analyzer 'Microsoft.DotNet.Analyzers.Compatibility.Deprecated.DeprecatedAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.DotNet.Analyzers.Compatibility.SymbolUsageAnalysisExtensions.Handle(SyntaxNodeAnalysisContext context, ExpressionSyntax node, Action`1 action)
   at Microsoft.DotNet.Analyzers.Compatibility.SymbolUsageAnalysisExtensions.Handle(SyntaxNodeAnalysisContext context, Action`1 action)
   at Microsoft.DotNet.Analyzers.Compatibility.SymbolUsageAnalysisExtensions.<>c__DisplayClass2_0.<RegisterSyntaxNodeAction>b__0(SyntaxNodeAnalysisContext nodeContext)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__43`1.<ExecuteSyntaxNodeAction>b__43_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
springy76 commented 6 years ago

Using 0.1.2 my ~80 projects solution had ~10 of such warnings, using 0.1.3 I now have 185. Using VS 15.5.5

pjanotti commented 6 years ago

Thanks for the detailed repro @nnpcYvIVl!

Thanks @nphmuller and @slozier for up-voting the issue, and @stringy76 for giving a measure of the impact.

Krakean commented 6 years ago

@pjanotti Can you please release hotfix to 0.1.3 alpha? Its a really critical issue that spam build output log very hard.