C# 正在引发System.ExecutionEngineeException
执行这行代码时会引发此异常C# 正在引发System.ExecutionEngineeException,c#,.net,.net-3.5,C#,.net,.net 3.5,执行这行代码时会引发此异常 retobj = Marshal.PtrToStructure( buffer, anytype ); 我不知道是什么原因导致了这种情况,因为我尝试运行的应用程序在这里的其他开发人员机器上运行良好 public static object RawDeserialize(byte[] rawdatas, Type anytype) { int rawsize = Marshal.SizeOf(anytype); if (rawsize > rawd
retobj = Marshal.PtrToStructure( buffer, anytype );
我不知道是什么原因导致了这种情况,因为我尝试运行的应用程序在这里的其他开发人员机器上运行良好
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;
}
我已多次尝试修复.NET Compact Framework,但似乎没有任何效果,有人知道解决方案吗?如果您要调试程序,您会发现以下行引发异常:
retobj = Marshal.PtrToStructure(buffer, anytype);
主要原因是封送工具不知道如何封送类型。这有很多可能的原因,我知道最常见的两个原因是:
- 通过在结构前面加上 [StructLayout(LayoutKind.Sequential,Pack=1)]
- 通过在数组前面加上 [Marshallas(UnmanagedType.ByValArray,SizeConst=512)]
希望有帮助。提供有关异常(以及任何
InnerException
)的更多信息。该异常在InnerException中是否有更多信息?内部异常为空<代码>公共静态对象RawDeserialize(byte[]rawdatas,Type anytype){int-rawsize=Marshal.SizeOf(anytype);if(rawsize>rawdatas.Length)返回null;IntPtr-buffer=Marshal.AllocHGlobal(rawsize);对象retobj=null;尝试{Marshal.Copy(rawdatas,0,buffer,rawsize);retobj=Marshal.PtrToStructure(buffer,anytype);}最后{Marshal.FreeHGlobal(buffer);}return retobj;}这是包含行的函数。除此之外,我不能提供更多的信息。你想在这里创建什么类型的对象?您可以发布您试图创建的对象的结构或类定义吗?@user501211,是否可以发布堆栈跟踪
?