简体   繁体   English

为什么带有嵌套数组的Marshal.PtrToStructure抛出ExecutionEngineException?

[英]Why does Marshal.PtrToStructure with nested arrays throw an ExecutionEngineException?

I am trying to convert a byte[] to a struct that contains an array of a struct that contains an array. 我正在尝试将byte []转换为包含包含数组的结构的数组的结构。

Something like this: 像这样:

[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct Util_VersionType 
{
      [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.LPStr, SizeConst = 5000)]
      public DataItemsString[] Data; 
}

[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct DataItemsString {
     [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 10)]
     public System.Byte[] Value;
     public System.UInt32 Validity;
}

I use Marshal.PtrToStructure 我使用Marshal.PtrToStructure

Sometimes there is no problem but in about 100 attempts the CLR throws an uncatchable ExecutionEngineException. 有时没有问题,但是在大约100次尝试中,CLR引发了不可捕获的ExecutionEngineException。

Please help. 请帮忙。 I'm lost. 我迷路了。

Looks like that this Exception is not related to the marshaling of the above structure directly. 看起来此Exception与上述结构的封送处理没有直接关系。

Please take a look in your code for cross accessing to the same instance by another thread. 请查看您的代码,以便通过另一个线程交叉访问同一实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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