Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

.NET 7 NRE in ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer #2817

Closed

Description

@jonathanpeppers

We are hitting an issue moving .NET MAUI to .NET 7. Happening at: dotnet/maui#7375

CSC error AD0001: Analyzer 'ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. 
CSC error AD0001: Analyzer 'ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. 

The full log shows:

CSC error AD0001: Analyzer 'ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. 

Exception occurred with following context:
Compilation: Microsoft.Maui.Controls.Compatibility
ISymbol: set_HasAlpha (Method)
System.NullReferenceException: Object reference not set to an instance of an object.
at ILLink.RoslynAnalyzer.ISymbolExtensions.TryGetAttribute(ISymbol member, String attributeName, AttributeData& attribute)
at ILLink.RoslynAnalyzer.ISymbolExtensions.GetDynamicallyAccessedMemberTypes(ISymbol symbol)
at ILLink.Shared.TrimAnalysis.FlowAnnotations.RequiresDataFlowAnalysis(IMethodSymbol method)
at ILLink.Shared.TrimAnalysis.FlowAnnotations.MethodRequiresDataFlowAnalysis(MethodProxy method)
at ILLink.Shared.TrimAnalysis.HandleCallAction.Invoke(MethodProxy calledMethod, ValueSet`1 instanceValue, IReadOnlyList`1 argumentValues, ValueSet`1& methodReturnValue, IntrinsicId& intrinsicId)
at ILLink.RoslynAnalyzer.TrimAnalysis.TrimAnalysisVisitor.HandleMethodCall(IMethodSymbol calledMethod, ValueSet`1 instance, ImmutableArray`1 arguments, IOperation operation)
at ILLink.RoslynAnalyzer.DataFlow.LocalDataFlowVisitor`2.VisitPropertyReference(IPropertyReferenceOperation operation, LocalDataFlowState`2 state)
at Microsoft.CodeAnalysis.Operations.PropertyReferenceOperation.Accept[TArgument,TResult](OperationVisitor`2 visitor, TArgument argument)
at ILLink.RoslynAnalyzer.DataFlow.OperationWalker`2.Visit(IOperation operation, TArgument argument)
at ILLink.RoslynAnalyzer.TrimAnalysis.TrimAnalysisVisitor.Visit(IOperation operation, LocalDataFlowState`2 argument)
at ILLink.RoslynAnalyzer.DataFlow.LocalDataFlowVisitor`2.VisitFlowCapture(IFlowCaptureOperation operation, LocalDataFlowState`2 state)
at Microsoft.CodeAnalysis.Operations.FlowCaptureOperation.Accept[TArgument,TResult](OperationVisitor`2 visitor, TArgument argument)
at ILLink.RoslynAnalyzer.DataFlow.OperationWalker`2.Visit(IOperation operation, TArgument argument)
at ILLink.RoslynAnalyzer.TrimAnalysis.TrimAnalysisVisitor.Visit(IOperation operation, LocalDataFlowState`2 argument)
at ILLink.RoslynAnalyzer.DataFlow.LocalDataFlowVisitor`2.Transfer(BlockProxy block, LocalDataFlowState`2 state)
at ILLink.Shared.DataFlow.ForwardDataFlowAnalysis`7.Fixpoint(TControlFlowGraph cfg, TLattice lattice, TTransfer transfer)
at ILLink.RoslynAnalyzer.TrimAnalysis.TrimDataFlowAnalysis.ComputeTrimAnalysisPatterns()
at ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer.<>c.<Initialize>b__5_1(OperationBlockAnalysisContext context)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)

Here is an example .binlog, look for errors under the <Csc/> task: maui-pack-Release.zip

Activity

  1. jonathanpeppers commented on Jun 1, 2022

    @jonathanpeppers
    MemberAuthor

    After looking at this more, it is failing in a net7.0-tizen project. As the error message suggested, I put this to workaround for now:

    <NoWarn>$(NoWarn);IL2026;IL2032;IL2041;IL2043;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</NoWarn>

    I'm not sure how much we support Tizen, but maybe this is a common pattern other code would hit?

  2. sbomer commented on Jun 1, 2022

    @sbomer
    Member

    Which error message do you mean? It might be better to temporarily add <NoWarn>$(NoWarn);AD0001</NoWarn> if you're still interested in getting trim warnings from the analyzer. Or to turn off the analyzer you can set <EnableTrimAnalyzer>false</EnableTrimAnalyzer>.

    But in general if you are seeing trim warnings, it's probably because you are building a project that has PublishTrimmed set to true, so the analyzer warnings may represent real issues and should probably be investigated.

    Would you be able to provide the ref assemblies this was being compiled against? I'm still not sure what is causing this nullref so I need to find a way to repro this.

  3. jonathanpeppers commented on Jun 2, 2022

    @jonathanpeppers
    MemberAuthor

    Thanks, I'll check if NoWarn=AD0001 works around the NRE.

    So I think the assembly you'd need would be the tizen version of:

    Compilation: Microsoft.Maui.Controls.Compatibility
    ISymbol: set_HasAlpha (Method)
    ...
    ISymbol: get_BackgroundColor (Method)
    

    I pulled these packs from our PR build:

  4. added a commit that references this issue on Jun 6, 2022
  5. sbomer commented on Jun 15, 2022

    @sbomer
    Member

    I wasn't able to repro it inside maui, but I think this is fixed by #2833. Please re-open if you continue to see this after building against a version with that fix.

  6. moved this to Done in AppModelon Jun 15, 2022
  7. added a commit that references this issue on Nov 11, 2022
  8. added a commit that references this issue on May 15, 2023
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

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions