Skip to content

Exception thrown when directly accessing property off of a constructed object #7

Description

@Emik03

The following ternary statement causes an exception to be thrown by this analyzer. You can find the surrounding context here.

HasSufficientMembers(raw)
    ? new Scaffolder(raw).Result
    : null;

Judging by the error, this should be enough information to fix the issue, but do let me know if you require me to create an MRE (Minimal Reproducible Example) otherwise:

CSC : warning AD0001: Analyzer 'Asyncify.VariableAccessAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.MethodSymbol' to type 'Microsoft.CodeAnalysis.ILocalSymbol'.'. [/home/emik/RiderProjects/Emik.SourceGenerators.Choices/Emik.SourceGenerators.Choices.csproj]
  Exception occurred with following context:
  Compilation: Emik.SourceGenerators.Choices
  SyntaxTree: /media/f/RiderProjects/Emik.SourceGenerators.Choices/Source/ExtendingGenerator.cs
  SyntaxNode: new Scaffolder(raw).Result [MemberAccessExpressionSyntax]@[3158..3184) (51,14)-(51,40)
  System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.MethodSymbol' to type 'Microsoft.CodeAnalysis.ILocalSymbol'.
  at Asyncify.VariableAccessChecker.FindSymbol(ExpressionSyntax expression)
  at Asyncify.VariableAccessChecker.ShouldUseTap(MemberAccessExpressionSyntax memberAccessExpression)
  at Asyncify.VariableAccessAnalyzer.CheckMemberAccess(SyntaxNodeAnalysisContext context)
  at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
  -----
  Suppress the following diagnostics to disable this analyzer: AsyncifyVariable

Thanks for taking the time in reading my issue!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions