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

Release inline optimization leads to MethodAccessException if used with assembly:InternalsVisibleTo attribute #16105

Closed
Lanayx opened this issue Oct 10, 2023 · 0 comments · Fixed by #16737
Assignees
Labels
Area-Compiler-CodeGen IlxGen, ilwrite and things at the backend Bug Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code.

Comments

@Lanayx
Copy link
Contributor

Lanayx commented Oct 10, 2023

We've faced an issue that internal function get inlined in the public one and this in turn leads to MethodAccessException on caller side.

Repro steps

Repro zip is attached. just run MethodAccessBug console application in Release mode (not reproduced in Debug)

MethodAccessBug.zip

Expected behavior

Call to internal function is not inlined an no exception is thrown

Actual behavior

Call to internal function is inlined an exception is thrown

Unhandled exception. System.MethodAccessException: Attempt by method '<StartupCode$MethodAccessBug>.$Program.main@()' to access method 'InternalLib.InternalModule.doSmth()' failed.
   at <StartupCode$MethodAccessBug>.$Program.main@() in C:\Temp\MethodAccessBug\MethodAccessBug\Program.fs:line 3

Known workarounds

Decorate public method with

[<MethodImpl(MethodImplOptions.NoInlining)>]

or with

[<NoCompilerInlining>]

Related information

  • Windows 11
  • .NET 7
@github-actions github-actions bot added this to the Backlog milestone Oct 10, 2023
@T-Gro T-Gro added Area-Compiler-CodeGen IlxGen, ilwrite and things at the backend and removed Needs-Triage labels Oct 23, 2023
@T-Gro T-Gro added the Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code. label Oct 23, 2023
@KevinRansom KevinRansom modified the milestones: Backlog, December-2023 Dec 9, 2023
@KevinRansom KevinRansom removed this from the February-2024 milestone Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-CodeGen IlxGen, ilwrite and things at the backend Bug Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code.
Projects
Archived in project
4 participants