Consider this F# program:
open System
[<Struct>]
type Image =
val data: voidptr
let LoadTextureFromMemory(): bool =
let image = Unchecked.defaultof<Image>
image.data = IntPtr.Zero.ToPointer()
let foo = LoadTextureFromMemory()
Expected behavior
This program should work and put true into the foo variable.
Actual behavior
Unhandled exception. System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)
at Program.LoadTextureFromMemory()
at <StartupCode$ConsoleApp11>.$Program.main@() in T:\Temp\ConsoleApp11\ConsoleApp11\Program.fs:line 13
See the repro on sharplab as well.
Known workarounds
// open Microsoft.FSharp.NativeInterop
NativePtr.ofVoidPtr<byte> image.data = NativePtr.nullPtr
Related information
- Operating system: Windows 11
- .NET Runtime kind (.NET Core, .NET Framework, Mono): .NET SDK 7.0.302
- Editing Tools (e.g. Visual Studio Version, Visual Studio): should not matter
Consider this F# program:
Expected behavior
This program should work and put
trueinto thefoovariable.Actual behavior
See the repro on sharplab as well.
Known workarounds
Related information