我注意到如果我用StructLayout.Sequential定义一个结构,就像这样:
open System.Runtime.InteropServices
[<StructLayout(LayoutKind.Sequential, Pack=1)>]
type SomeType =
val mutable Field1: uint32
val mutable Field2: uint32
这在实际程序中编译并正常工作,但FSI提供错误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.
这是FSI的错误还是限制?有解决方法吗?
答案 0 :(得分:5)
解决方法(错误有提示):
[<Struct;StructLayout(LayoutKind.Explicit)>]
type SomeType =
[<FieldOffset(0)>]
val mutable Field1: uint32
[<FieldOffset(4)>]
val mutable Field2: uint32