F# interactive Marshal.SizeOf with Mono 抛出“断言”错误
F# interactive Marshal.SizeOf with Mono throws “assertion” error
我试图在 Mac OSX 上使用 Mono 5.8 使用 F# 将 GIF 文件头读入结构。以下代码示例在 Windows 10 的 Visual Studio 2017 中运行良好;但是,当我尝试在 Visual Studio 中为 Mac 运行 时,我在 F# interactive 中收到以下错误:
* Assertion at class-accessors.c:138, condition `mono_class_has_static_metadata (klass)' not met
我使用的代码如下。结构可能不正确,因为我只是为了这个问题快速拼凑起来,但是
open System
open System.IO
open System.Runtime.InteropServices
[<Struct; StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)>]
type GifHeader = {
[<MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)>]
signature: string
[<MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)>]
version: string
logicalWidth: int16
logicalHeight: int16
}
当我在 Visual Studio 中为 Mac 的 FSI 调用 Marshal.SizeOf(typeof<GifHeader>)
时,出现上述错误。
我注意到当我读入如下结构时:
[<Struct; StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)>]
type SomeOtherHeader = {
field1: uint16
field2: int32
field3: int16
field4: float
}
即如果没有 MarshalAs UnmanagedType 规范,则不会引发错误。
有谁知道这个错误是什么意思?我在 Google 或其他 SE 帖子上没有看到此特定错误的任何其他实例,这尤其令人费解,因为它不会发生在 Windows/.NET Framework 4.7 上。没有交互式 window 来测试代码是学习的巨大障碍,而且非常令人沮丧,因为我认为不可能使用替代的(非单声道)FSI。
这是当前 Mono 版本固有的问题。根据 Mono 团队,此问题已从 Mono 5.14 开始修复。
我试图在 Mac OSX 上使用 Mono 5.8 使用 F# 将 GIF 文件头读入结构。以下代码示例在 Windows 10 的 Visual Studio 2017 中运行良好;但是,当我尝试在 Visual Studio 中为 Mac 运行 时,我在 F# interactive 中收到以下错误:
* Assertion at class-accessors.c:138, condition `mono_class_has_static_metadata (klass)' not met
我使用的代码如下。结构可能不正确,因为我只是为了这个问题快速拼凑起来,但是
open System
open System.IO
open System.Runtime.InteropServices
[<Struct; StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)>]
type GifHeader = {
[<MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)>]
signature: string
[<MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)>]
version: string
logicalWidth: int16
logicalHeight: int16
}
当我在 Visual Studio 中为 Mac 的 FSI 调用 Marshal.SizeOf(typeof<GifHeader>)
时,出现上述错误。
我注意到当我读入如下结构时:
[<Struct; StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)>]
type SomeOtherHeader = {
field1: uint16
field2: int32
field3: int16
field4: float
}
即如果没有 MarshalAs UnmanagedType 规范,则不会引发错误。
有谁知道这个错误是什么意思?我在 Google 或其他 SE 帖子上没有看到此特定错误的任何其他实例,这尤其令人费解,因为它不会发生在 Windows/.NET Framework 4.7 上。没有交互式 window 来测试代码是学习的巨大障碍,而且非常令人沮丧,因为我认为不可能使用替代的(非单声道)FSI。
这是当前 Mono 版本固有的问题。根据 Mono 团队,此问题已从 Mono 5.14 开始修复。