-
Notifications
You must be signed in to change notification settings - Fork 847
Closed
Labels
Impact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.(Internal MS Team use only) Describes an issue with extreme impact on existing code.Regression
Milestone
Description
Since the 16.10.0 VS update, the below code produces a BadImageFormatException. Prior to that release, it works as expected.
Repro steps
module Repro
type Data = interface end
and Service<'Data when 'Data :> Data>() = class end
type IThing = interface end
and Thing<'T> = { Metadata: 'T } with interface IThing
let createService metadata = (Service<'Data>())
let getCreateServiceCallback<'T> (thing: IThing) =
let upcastThing =
thing
:?> Thing<'T>
let getService () = createService upcastThing.Metadata
(fun () -> getService)
[<EntryPoint>]
let main _ =
let dummyThing : Thing<int> = { Thing.Metadata = 42 }
// crash occurs on the following line
let callback = getCreateServiceCallback<int> dummyThing
let resolvedService = 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
getServicefunction asinline - Explicitly annotating the
getServicereturn type asService<Data> - Run in release mode
Related information
- Windows 10
- .NET 5
- Visual Studio 2019
Metadata
Metadata
Assignees
Labels
Impact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.(Internal MS Team use only) Describes an issue with extreme impact on existing code.Regression