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

MethodAccessException on equality comparison of a record with private fields when building from VS 17.11.5 #17925

Closed
OkkeHendriks opened this issue Oct 25, 2024 · 11 comments
Labels
Milestone

Comments

@OkkeHendriks
Copy link

Please provide a succinct description of the issue.

MethodAccessException on equality comparison of a record with private fields but only when building from visual studio (17.11.5).
This is (probably) somehow related to this issue #17447
The SDK should be pinned at 8.0.300 by the global.json file, this version should not have this problem I believe.

Provide the steps required to reproduce the problem:

Currently installed sdks and runtimes:

okkhen@CLNT7418:/d/git/equals
@ main$ dotnet --list-sdks
8.0.300 [C:\Program Files\dotnet\sdk]
8.0.304 [C:\Program Files\dotnet\sdk]
8.0.306 [C:\Program Files\dotnet\sdk]
8.0.403 [C:\Program Files\dotnet\sdk]
okkhen@CLNT7418:/d/git/equals
@ main$ dotnet --list-runtimes
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  1. Rebuilding the solution in this reproduction repository from within visual studio. Version info:
Microsoft Visual Studio Enterprise 2022
Version 17.11.5
VisualStudio.17.Release/17.11.5+35327.3
Microsoft .NET Framework
Version 4.8.09037

Installed Version: Enterprise

Visual C++ 2022   00476-80000-00000-AA437
Microsoft Visual C++ 2022

ASP.NET and Web Tools   17.11.231.19466
ASP.NET and Web Tools

Azure App Service Tools v3.0.0   17.11.231.19466
Azure App Service Tools v3.0.0

C# Tools   4.11.0-3.24460.3+5649376e0e5f5db3743a94a62b073f2cce4be5d9
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

GitHub Copilot   0.2.1657.32929
GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.

Microsoft Azure Tools for Visual Studio   2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager   6.11.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core)   17.11.3.2442001+68650a7d94261bc56a1f4bc522c2ee35314b1abb
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.11.47.0
Microsoft SQL Server Data Tools

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools   17.0.30715.2002
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.11.0-3.24460.3+5649376e0e5f5db3743a94a62b073f2cce4be5d9
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.11.0-beta.24421.7+af2f522de602281d4ef5a7b71507c428e814c5c1
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.
  1. Execute Console.exe (from the command line).

Expected behavior

@ main$ Console/bin/Debug/net8.0/Console.exe
Comparing two values from a defined in a referenced library with a private constructor.
Not equal

Actual behavior

Comparing two values from a defined in a referenced library with a private constructor.
Unhandled exception. System.MethodAccessException: Attempt by method 'Program.main(System.String[])' to access method 'LibA+TypeWithPrivateConstructor.Equals(TypeWithPrivateConstructor, System.Collections.IEqualityComparer)' failed.
   at Program.main(String[] _arg1) in D:\git\equals\Console\Program.fs:line 9

Known workarounds

  1. Build from command line dotnet build equals.sln.

Now it simply runs as expected.

Related information

I added the following log target to the project files:

  <Target Name="WhichSDK" BeforeTargets="Build" >
    <Message Importance="high" Text="$(MSBuildProjectName): using .NET Core SDK: $(NETCoreSdkVersion)" />
  </Target>

Which prints the expected 8.0.300 SDK version. Both when building from Visual Studio or from the CLI.

Additionally the installed sdks/runtimes:
Image

Any pointer as to what could cause this or how to further investigate?

@OkkeHendriks
Copy link
Author

I just tried installing visual studio preview 17.12.0 preview 4.0.
When building from within this VS version I do get the expected output and do not hit the bug.

Microsoft Visual Studio Enterprise 2022
Version 17.12.0 Preview 4.0
VisualStudio.17.Preview/17.12.0-pre.4.0+35417.141
Microsoft .NET Framework
Version 4.8.09037

Installing the preview installed an additional SDK and runtime, the list:

@ main$ dotnet --list-sdks
8.0.300 [C:\Program Files\dotnet\sdk]
8.0.304 [C:\Program Files\dotnet\sdk]
8.0.306 [C:\Program Files\dotnet\sdk]
8.0.403 [C:\Program Files\dotnet\sdk]
9.0.100-rc.2.24474.11 [C:\Program Files\dotnet\sdk]
okkhen@CLNT7418:/d/git/equals
@ main$ dotnet --list-runtimes
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
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 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.8 [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 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.8 [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]

Image

It seems that somehow VS 17.11.5 is using the wrong SDK version?

@OkkeHendriks OkkeHendriks changed the title MethodAccessException on equality comparison of a record with private fields when building from visual studio MethodAccessException on equality comparison of a record with private fields when building from VS 17.11.5 Oct 25, 2024
@vzarytovskii
Copy link
Member

Yeah, it's the same issue and was fixed in the later VS

@OkkeHendriks
Copy link
Author

What I don’t understand is that it should build using the SDK indicated by ‘global.json’ right?

@vzarytovskii
Copy link
Member

What I don’t understand is that it should build using the SDK indicated by ‘global.json’ right?

It should, yes, but it might theoretically pick different locations for compiler itself (shipped with VS vs standalone) as well as different compilers (desktop/coreclr), it's currently hard to say what compiler was picked up for which version without binlog, we have quite complex logic for that.

@OkkeHendriks
Copy link
Author

I think for me personally I can work around this until the next VS release, however if I can help by providing additional information I am happy to do so.

I followed https://github.com/dotnet/project-system-tools?tab=readme-ov-file#getting-higher-fidelity-logs-from-vs-vs2022-onwards
and performed a build of the reproduction project to obtain a binlog.

Not sure which of these files are interesting (and how to best share them here 😄) ?
Image

@vzarytovskii
Copy link
Member

I think for me personally I can work around this until the next VS release, however if I can help by providing additional information I am happy to do so.

I followed https://github.com/dotnet/project-system-tools?tab=readme-ov-file#getting-higher-fidelity-logs-from-vs-vs2022-onwards and performed a build of the reproduction project to obtain a binlog.

Not sure which of these files are interesting (and how to best share them here 😄) ? Image

You can share them via email probably, sending to fsharp[at]microsoft.com, so we can look into it when we'll get to it. Thanks in advance!

@OkkeHendriks
Copy link
Author

I am not on the allowed senders list it seems, I can send it to your private email if that is ok with you?

@vzarytovskii
Copy link
Member

I am not on the allowed senders list it seems, I can send it to your private email if that is ok with you?

Yeah, it's vlza + same domain.

@baronfel
Copy link
Member

Consider creating a ticket on VS developer community - you can upload them privately there and the team can access them.

@OkkeHendriks
Copy link
Author

Done: https://developercommunity.visualstudio.com/t/It-seems-that-globaljson-is-ignored-ca/10780523

@abonie
Copy link
Member

abonie commented Nov 11, 2024

We'll triage and investigate the community feedback issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

4 participants