Skip to content

RoslynAnalyzer crashes after changing target framework to net10.0 #121546

@nrudakov

Description

@nrudakov

Description

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.PropertySymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.'. [D:\MyProject.csproj::TargetFramework=net10.0]
  1:18>Exception occurred with following context:
         Compilation: MyProject
         ISymbol: this[] (Property)
         System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.PropertySymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.
         at ILLink.RoslynAnalyzer.TrimAnalysis.TrimAnalysisVisitor.GetParameterTargetValue(IParameterSymbol parameter)
         at ILLink.RoslynAnalyzer.DataFlow.LocalDataFlowVisitor`5.ProcessSingleTargetAssignment(IOperation targetOperation, IOperation valueOperation, IOperation assignmentOperation, LocalDataFlowState`4 state, Boolean merge)
         at ILLink.RoslynAnalyzer.DataFlow.LocalDataFlowVisitor`5.ProcessAssignment(IAssignmentOperation operation, LocalDataFlowState`4 state)
         at ILLink.RoslynAnalyzer.DataFlow.OperationWalker`2.Visit(IOperation operation, TArgument argument)
         at ILLink.RoslynAnalyzer.DataFlow.LocalDataFlowVisitor`5.Transfer(BlockProxy block, LocalDataFlowState`4 state)
         at ILLink.Shared.DataFlow.ForwardDataFlowAnalysis`8.TransferOut(TTransfer transfer, TControlFlowGraph cfg, TBlock block, TState state, Action`2 updateState)
         at ILLink.Shared.DataFlow.ForwardDataFlowAnalysis`8.Fixpoint(TControlFlowGraph cfg, TTransfer transfer)
         at ILLink.RoslynAnalyzer.DataFlow.LocalDataFlowAnalysis`6.AnalyzeMethod(MethodBodyValue method, InterproceduralState`2& interproceduralState)
         at ILLink.RoslynAnalyzer.DataFlow.LocalDataFlowAnalysis`6.InterproceduralAnalyze()
         at ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer.<>c__DisplayClass13_0.<Initialize>b__1(OperationBlockAnalysisContext 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: IL2026, IL2032, IL2041, IL2043, IL2046, IL2055, IL2057, IL2058, IL2059, IL2060, IL2062, IL2063, IL2064, IL2065, IL2066, IL2067, IL2068, IL2069, IL2070, IL2071, IL2072, IL2073, IL2074, IL2075, IL2076, IL2077, IL2078, IL2079, IL2080, IL2081, IL2082, IL2083, IL2084, IL2085, IL2086, IL2087, IL2088, IL2089, IL2090, IL2091, IL2092, IL2093, IL2094, IL2095, IL2096, IL2097, IL2098, IL2099, IL2103, IL2106, IL2110, IL2111, IL2112, IL2113, IL2114, IL2115, IL2116, IL2122, IL2123, IL2124, IL2125, IL2126, IL3000, IL3001, IL3002, IL3003, IL3004, IL3005, IL3050, IL3051, IL3056, IL3057, IL3058, IL4000, IL4001

Reproduction Steps

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net10.0</TargetFrameworks>
    <Platforms>x64</Platforms>
    <PlatformTarget>x64</PlatformTarget>
    
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <AnalysisLevel>latest-all</AnalysisLevel>
    <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
    <WarningLevel>8</WarningLevel>
    <TreatWarningsAsErrors>True</TreatWarningsAsErrors>

    <IsAotCompatible>True</IsAotCompatible>
  </PropertyGroup>
</Project>

Expected behavior

Project builds

Actual behavior

Project build fails because of analyzer crash

Regression?

No response

Known Workarounds

No response

Configuration

.NET 10.0, Windows 11, x64

Other information

No response

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzers

Type

No type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions