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

AD0001 - NullReferenceException when running CA2246 #2889

Closed
RobSiklos opened this issue Oct 2, 2019 · 7 comments · Fixed by #2894
Closed

AD0001 - NullReferenceException when running CA2246 #2889

RobSiklos opened this issue Oct 2, 2019 · 7 comments · Fixed by #2894
Assignees
Labels
Bug The product is not behaving according to its current intended design Category-Usage Urgency-Soon

Comments

@RobSiklos
Copy link

RobSiklos commented Oct 2, 2019

Analyzer package

Microsoft.CodeAnalysis.FxCopAnalyzers

Package Version

v2.9.5

Diagnostic ID

CA2246

Repro steps

Analyze the following code:

public static class Class1
{
    public static void Foo()
    {
        var u = new System.UriBuilder();
        u.Host = u.Path = string.Empty;
    }
}

Expected behavior

No warning or error.

Actual behavior

Analyzer 'Microsoft.CodeQuality.Analyzers.QualityGuidelines.AssigningSymbolAndItsMemberInSameStatement' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'

Analyzer 'Microsoft.CodeQuality.Analyzers.QualityGuidelines.AssigningSymbolAndItsMemberInSameStatement' threw the following exception:
'Exception occurred with following context:
Compilation: RoslynAnalyzersFalsePositives
IOperation: SimpleAssignment
SyntaxTree: D:\src\Rob\RoslynAnalyzersFalsePositives\RoslynAnalyzersFalsePositives\CA2246.cs
SyntaxNode: u.Host = u.Path = string.Empty [AssignmentExpressionSyntax]@[193..223) (7,12)-(7,42)

System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.CodeQuality.Analyzers.QualityGuidelines.AssigningSymbolAndItsMemberInSameStatement.<>c.b__8_0(ILocalReferenceOperation a, ILocalReferenceOperation b)
at Microsoft.CodeQuality.Analyzers.QualityGuidelines.AssigningSymbolAndItsMemberInSameStatement.AnalyzeAssignmentToMember[T](ISimpleAssignmentOperation assignmentOperation, T instance, Func3 equalityComparer) at Microsoft.CodeQuality.Analyzers.QualityGuidelines.AssigningSymbolAndItsMemberInSameStatement.AnalyzeAssignment(OperationAnalysisContext context) at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteOperationAction>b__54_0(ValueTuple2 data)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action1 analyze, TArg argument, Nullable1 info)

@mavasani
Copy link
Member

mavasani commented Oct 2, 2019

Thanks for the prompt bug report @RobSiklos. I will work on a fix and point you a myget package with the fix. Based on number of folks that hit this, we may have to release a 2.9.6-beta1 or 2.9.6 for this fix.

@mavasani mavasani self-assigned this Oct 2, 2019
@mavasani mavasani added Area-Microsoft.CodeQuality.Analyzers Bug The product is not behaving according to its current intended design Category-Usage Urgency-Soon labels Oct 2, 2019
@mavasani mavasani added this to the vNext milestone Oct 2, 2019
mavasani added a commit to mavasani/roslyn-analyzers that referenced this issue Oct 2, 2019
@RobSiklos
Copy link
Author

Confirmed fixed in 2.9.6-beta1.19502.2+ce473561. Thanks @mavasani !

@mavasani
Copy link
Member

mavasani commented Oct 3, 2019

FYI: We got large number of customer reports for this AD0001. So, we have just published 2.9.6 with this fix: https://github.com/dotnet/roslyn-analyzers/releases/tag/v2.9.6

Thanks everyone for helping find and fix this issue promptly.

@adamralph
Copy link
Contributor

I'm using 2.10.0 and I'm still having this problem.

@adamralph
Copy link
Contributor

Sorry, it's a different error message. I guess I'll raise a new issue...

@adamralph
Copy link
Contributor

#1803 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The product is not behaving according to its current intended design Category-Usage Urgency-Soon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants