Skip to content

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

@Lanayx

Description

@Lanayx

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

Metadata

Metadata

Assignees

Labels

Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendBugImpact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions