Skip to content

ILLink.RoslynAnalyzer throws System.InvalidCastException with C# 14 extensions and targeting net9.0 #120728

@meziantou

Description

@meziantou

Description

Analyzer throws an exception when building a project using new extensions syntax.

  • The exception occurs when targeting net9.0
  • Change it to net8.0 or net10.0 and the error vanish

I think #115949 fixed a part of the error, but the error still occurs when targeting net9.0.

Reproduction Steps

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<TargetFramework>net9.0</TargetFramework>
		<LangVersion>preview</LangVersion>
		<IsTrimmable>true</IsTrimmable>
	</PropertyGroup>
</Project>
public static class ArrayExtensions
{
    extension<T>(T[] array)
    {
        public int Count => array.Length;
    }
}

warning 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.NonErrorNamedTypeSymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.'.

Expected behavior

No exception

Actual behavior

An exception is thrown

Regression?

No response

Known Workarounds

No response

Configuration

  • .NET 10 RC2 (10.0.100-rc.2.25502.107)

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area ownersuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions