Skip to content

DynamicallyAccessedMembersAnalyzer throws an internal exception due to source location outside compilation #109352

Closed

Description

@AArnott

Describe the bug

In enabling the AOT readiness analyzers, the MessagePack codebase produces a lot of warnings. Among them is an AD0001 warning about a failed analyzer. See Exceptions section for details.

To Reproduce

git clone https://github.com/MessagePack-CSharp/MessagePack-CSharp.git
cd MessagePack-CSharp
git checkout dotnet/sdk/bug44120repro
.\MessagePack.sln

Inspect the error list, filtering to AD0001 entries.

Exceptions (if any)

Analyzer 'ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer' threw an exception of type 'System.ArgumentException' with message 'Reported diagnostic 'IL2075' has a source location in file 'Q:\source\MessagePack-CSharp\src\MessagePack.Annotations\Attributes.cs', which is not part of the compilation being analyzed. (Parameter 'diagnostic')'.
Exception occurred with following context:
Compilation: MessagePack
ISymbol: BuildCustomFormatterField (Method)

System.ArgumentException: Reported diagnostic 'IL2075' has a source location in file 'Q:\source\MessagePack-CSharp\src\MessagePack.Annotations\Attributes.cs', which is not part of the compilation being analyzed. (Parameter 'diagnostic')
   at Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalysisContextHelpers.VerifyDiagnosticLocationInCompilation(String id, Location location, Compilation compilation)
   at Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalysisContextHelpers.VerifyDiagnosticLocationsInCompilation(Diagnostic diagnostic, Compilation compilation)
   at Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalysisContextHelpers.VerifyArguments(Diagnostic diagnostic, Compilation compilation, Func`3 isSupportedDiagnostic, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Diagnostics.OperationBlockAnalysisContext.ReportDiagnostic(Diagnostic diagnostic)
   at ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer.<>c.<Initialize>b__8_1(OperationBlockAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)

Further technical details

  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Oct 11, 2024
  2. transferred this issue fromdotnet/sdkon Oct 29, 2024
  3. ghost added
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Oct 29, 2024
  4. removed
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Oct 30, 2024
  5. JulieLeeMSFT commented on Nov 6, 2024

    @JulieLeeMSFT
    Member
  6. JulieLeeMSFT commented on Nov 6, 2024

    @JulieLeeMSFT
    Member

    @agocke, please see if this is an ILLInk related issue.

  7. added this to the 10.0.0 milestone on Nov 8, 2024
  8. removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 8, 2024
  9. 13 remaining items

  10. jtschuster commented on Nov 14, 2024

    @jtschuster
    Member

    Warnings don't show up for me until I open source files. When I open DynamicObjectResolver.cs and MessagePack.Annotations\Attributes.cs, with no build I still can't get the AD0001. Which files do you have open when you get the AD0001 error? Or do you have a setting that turns on analysis on for unopened files?

  11. AArnott commented on Nov 14, 2024

    @AArnott
    ContributorAuthor

    Or do you have a setting that turns on analysis on for unopened files?

    I definitely have this setting in my IDE.

  12. jtschuster commented on Nov 14, 2024

    @jtschuster
    Member

    Thank you, that did it, I can repro now. Now to investigate why..

  13. removed
    needs-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration
    on Nov 22, 2024
  14. sbomer commented on Jun 10, 2025

    @sbomer
    Member

    @jtschuster did you end up getting any more insight into this? If you still have a repro handy it would be great if you could share it for future reference.

  15. jtschuster commented on Jun 10, 2025

    @jtschuster
    Member

    I wasn't able to find the root cause. I haven't checked recent builds, but the repro in the original message worked once I set VS to run analysis on unopened files.

  16. modified the milestones: 10.0.0, 11.0.0 on Aug 4, 2025
  17. assigned and unassigned on Aug 3, 2026
  18. added a commit that references this issue on Aug 11, 2026
    00457c4
  19. locked and limited conversation to collaborators on Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions