简体   繁体   中英

StructLayout limitation in F# Interactive?

I noticed that if I define a struct with StructLayout.Sequential, like so:

open System.Runtime.InteropServices

[<StructLayout(LayoutKind.Sequential, Pack=1)>]
type SomeType =
 val mutable Field1: uint32
 val mutable Field2: uint32

This compiles and works fine in a real program, but FSI gives error error FS0193: internal error: Could not load type 'SomeType' from assembly 'FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because field 'Field1' was not given an explicit offset.

Is this a bug or limitation of FSI? Is there a workaround?

Workaround (the error has a hint):

[<Struct;StructLayout(LayoutKind.Explicit)>]
type SomeType =
    [<FieldOffset(0)>]
    val mutable Field1: uint32
    [<FieldOffset(4)>]
    val mutable Field2: uint32

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM