Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AArnott opened this issue Oct 11, 2024 · 17 comments
Assignees
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Milestone

Comments

@AArnott
Copy link
Contributor

AArnott commented Oct 11, 2024

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
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Oct 11, 2024
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@baronfel baronfel transferred this issue from dotnet/sdk Oct 29, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 29, 2024
@vcsjones vcsjones removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 30, 2024
@JulieLeeMSFT
Copy link
Member

CC @amanasifkhalid.

@JulieLeeMSFT
Copy link
Member

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

@agocke agocke added area-Tools-ILLink .NET linker development as well as trimming analyzers and removed area-ILTools-coreclr labels Nov 8, 2024
@agocke agocke added this to the 10.0.0 milestone Nov 8, 2024
@agocke agocke removed the untriaged New issue has not been triaged by the area owner label Nov 8, 2024
@agocke
Copy link
Member

agocke commented Nov 8, 2024

@jtschuster could you take a look?

@jtschuster
Copy link
Member

I'm unable to reproduce this. Does this occur in VS only, or command line builds too? What version for the .NET SDK and VS are you using?

@jtschuster jtschuster added the needs-author-action An issue or pull request that requires more info or actions from the author. label Nov 11, 2024
@AArnott
Copy link
Contributor Author

AArnott commented Nov 11, 2024

@jtschuster This repros for me just now with Visual Studio Version 17.13.0 Preview 1.0 [35429.394.main].

It can be helpful to filter your Error List to just AD0001 warnings to find it:
Image

dotnet --info
dotnet --info
.NET SDK:
 Version:           8.0.403
 Commit:            c64aa40a71
 Workload version:  8.0.400-manifests.42a6cf86
 MSBuild version:   17.11.9+a69bbaaf5

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26100
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.403\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

Host:
  Version:      9.0.0-rc.2.24473.5
  Architecture: x64
  Commit:       990ebf52fc

.NET SDKs installed:
  8.0.403 [C:\Program Files\dotnet\sdk]
  9.0.100-rc.2.24474.11 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-rc.2.24474.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-rc.2.24473.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0-rc.2.24474.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  D:\source\MessagePack-CSharp\global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

@dotnet-policy-service dotnet-policy-service bot added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Nov 11, 2024
@jtschuster
Copy link
Member

I'm trying to figure out how to install 17.13.0 Preview 1.0, but on 17.13.0 Preview 2.0, the IL2075 warning location is MessagePack-CSharp\src\MessagePack\Resolvers\DynamicObjectResolver.cs:401, which is where it should be and is in the compilation. Maybe this is a Roslyn issue that got resolved between preview versions? If you upgrade to Preview 2.0, does it persist?

@AArnott
Copy link
Contributor Author

AArnott commented Nov 13, 2024

@jtschuster The bug still repros on 17.13 Preview 2 (35511.228.main):

Analyzer 'ILLink.RoslynAnalyzer.DynamicallyAccessedMembersAnalyzer' threw an exception of type 'System.ArgumentException' with message 'Reported diagnostic 'IL2075' has a source location in file 'D:\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 'D:\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, Func3 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, Action1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)

@sbomer
Copy link
Member

sbomer commented Nov 13, 2024

I'm not able to repro the issue either - @AArnott are you able to repro this on another machine?

@AArnott
Copy link
Contributor Author

AArnott commented Nov 13, 2024

I've already repro'd it on 2 distinct machines.

@sbomer
Copy link
Member

sbomer commented Nov 13, 2024

Still can't repro on a fresh dev box. However, I do notice that the IL2075 warning shows up in a command-line build, but not in the error list. Maybe the AD0001 is getting swallowed somehow in our setup. @jtschuster do you see the warning in the error list or on the command-line?

@jtschuster
Copy link
Member

I see the IL2075 in DynamicObjectResolver.cs in the VS error list, but only (usually) on a rebuild or (consistently) after a git clean -xdf.

@AArnott
Copy link
Contributor Author

AArnott commented Nov 14, 2024

FWIW I see the AD0001 error without any build at all. Just open the sln on a clean repo and wait a couple minutes. A flood of entries appear in the Error List, so I then apply the column filter to show only the (1) AD0001 error and it shows up.

@jtschuster
Copy link
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?

@AArnott
Copy link
Contributor Author

AArnott commented Nov 14, 2024

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

I definitely have this setting in my IDE.

@jtschuster
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
Status: No status
Development

No branches or pull requests

8 participants