[英]System.ExecutionEngineException being thrown
This exception is being thrown when this line of code gets executed 执行此代码行时会抛出此异常
retobj = Marshal.PtrToStructure( buffer, anytype );
I don't know what is causing this because, the application I am attempting to run works fine on other developers machines here. 我不知道是什么原因造成的,因为我试图运行的应用程序在其他开发者机器上工作正常。
public static object RawDeserialize(byte[] rawdatas, Type anytype)
{
int rawsize = Marshal.SizeOf(anytype);
if (rawsize > rawdatas.Length)
{
return null;
}
IntPtr buffer = Marshal.AllocHGlobal(rawsize);
object retobj = null;
try
{
Marshal.Copy(rawdatas, 0, buffer, rawsize);
retobj = Marshal.PtrToStructure(buffer, anytype);
}
finally
{
Marshal.FreeHGlobal(buffer);
}
return retobj;
}
I've tried repairing the .NET Compact Framework multiple times and nothing seems to work, does anyone know of a solution to this? 我已经多次尝试修复.NET Compact Framework,似乎没有任何工作,有没有人知道这个解决方案?
If you'll debug your program you'll find out that the following line throws the exception: 如果您将调试您的程序,您将发现以下行引发异常:
retobj = Marshal.PtrToStructure(buffer, anytype);
The main cause is that the marshalling tool does not know how to marshal your type. 主要原因是编组工具不知道如何编组你的类型。 This has many possible causes, two of the most common I know are: 这有很多可能的原因,我知道最常见的两个原因是:
Nested structures in the struct (of type anytype) 结构中的嵌套结构(类型为anytype)
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential,Pack = 1)]
Nested arrays. 嵌套数组。
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] [MarshalAs(UnmanagedType.ByValArray,SizeConst = 512)]
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.