Skip to content

AD0001: Analyzer 'ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer' threw an exception of type 'System.InvalidCastException' #3106

@MackinnonBuck

Description

@MackinnonBuck

Describe the bug

Annotating a parameter on a local function with [DynamicallyAccessedMembers] causes ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer to throw the following exception:

CSC : error AD0001: Analyzer 'ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer' 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.ITypeSymbol'.'.

This was observed in dotnet/aspnetcore#44925. The culprit was this line.

SDK version with the bug:
8.0.100-alpha.1.22556.1

Last known SDK version without the bug:
8.0.100-alpha.1.22531.1

Steps to reproduce

  1. Checkout https://github.com/dotnet/aspnetcore/tree/98bd1e8085ba090a352ed1eda7f86fd2bd5381ea
  2. Build the solution following these steps

Expected behavior

The build completes successfully.

Actual behavior

The build fails with the aforementioned error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions