fsharp
fsharp copied to clipboard
Release inline optimization leads to MethodAccessException if used with assembly:InternalsVisibleTo attribute
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)
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