This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
.NET 7 NRE in ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer #2817
Copy link
Copy link
Closed
Description
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
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
- StatusShow more project fieldsDone
Activity
jonathanpeppers commentedon Jun 1, 2022
After looking at this more, it is failing in a
net7.0-tizenproject. As the error message suggested, I put this to workaround for now:I'm not sure how much we support Tizen, but maybe this is a common pattern other code would hit?
sbomer commentedon Jun 1, 2022
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
PublishTrimmedset totrue, 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.
jonathanpeppers commentedon Jun 2, 2022
Thanks, I'll check if
NoWarn=AD0001works around the NRE.So I think the assembly you'd need would be the tizen version of:
I pulled these packs from our PR build:
Update to .NET 7 SDKs (#7375)
sbomer commentedon Jun 15, 2022
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.
[net7.0] remove $(NoWarn) for AD0001
[net7.0] remove $(NoWarn) for AD0001 (#9605)
Merge net7 (#11279)
Update to .NET 7 SDKs (#7375)