Since the 16.10.0 VS update, the below code produces a BadImageFormatException. Prior to that release, it works as expected.
Repro steps
moduleReprotypeData=interfaceendandService<'Datawhen'Data:>Data>()=classendtypeIThing=interfaceendandThing<'T>={ Metadata:'T }withinterface IThing
letcreateService metadata =(Service<'Data>())letgetCreateServiceCallback<'T>(thing:IThing)=letupcastThing=
thing
:?> Thing<'T>letgetService()= createService upcastThing.Metadata
(fun()-> getService)[<EntryPoint>]letmain _ =letdummyThing:Thing<int>={ Thing.Metadata =42}// crash occurs on the following lineletcallback= getCreateServiceCallback<int> dummyThing
letresolvedService= callback ()
printfn "Resolved service: %A" resolvedService
System.Console.ReadKey()|> ignore
0Expected behavior
Code should work as it did prior to 16.10.0, or at least produce a compiler error.
Actual behavior
Crashes with BadImageFormatException on the indicated line.
Known workarounds
- Marking the
getService function as inline - Explicitly annotating the
getService return type as Service<Data> - Run in release mode
Related information
- Windows 10
- .NET 5
- Visual Studio 2019
Since the 16.10.0 VS update, the below code produces a
BadImageFormatException. Prior to that release, it works as expected.Repro steps
Expected behavior
Code should work as it did prior to 16.10.0, or at least produce a compiler error.
Actual behavior
Crashes with
BadImageFormatExceptionon the indicated line.Known workarounds
getServicefunction asinlinegetServicereturn type asService<Data>Related information