dotnet / linker

388 stars 126 forks source link

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

Closed MackinnonBuck closed 1 year ago

MackinnonBuck commented 1 year ago

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 https://github.com/dotnet/aspnetcore/pull/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.

sbomer commented 1 year ago

Corresponds to this commit range: https://github.com/dotnet/linker/compare/4db6ac94ffa8bf6dae8ad9c5c68f94b58de917fd...391ac60bbfb2c618b82f08af728d2d4d259d584e#.

I think this cast is the issue - when the method is a local function, its containing symbol might be a method. @jtschuster would you mind taking a look?

JamesNK commented 1 year ago

FYI this issue impacts the dotnet/aspnetcore repository and blocks us from updating the SDK. It's not urgent to update the SDK, but prompt progress would be appreciated.

jtschuster commented 1 year ago

The fix is checked in and flowing to sdk in https://github.com/dotnet/sdk/pull/29013

jtschuster commented 1 year ago

The change should now be in the installer repo from https://github.com/dotnet/installer/pull/14951, but that build failed to publish https://dev.azure.com/dnceng/internal/_build/results?buildId=2042975&view=results.

jtschuster commented 1 year ago

Closing since it looks like there's a separate issue holding up the ASP.Net PR