简体   繁体   中英

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.

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

Sometimes there is no problem but in about 100 attempts the CLR throws an uncatchable ExecutionEngineException.

Please help. I'm lost.

Looks like that this Exception is not related to the marshaling of the above structure directly.

Please take a look in your code for cross accessing to the same instance by another thread.

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