简体   繁体   English

抛出System.ExecutionEngineException

[英]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: 这有很多可能的原因,我知道最常见的两个原因是:

  1. Nested structures in the struct (of type anytype) 结构中的嵌套结构(类型为anytype)

    • solved by prefixing your struct with 通过为结构添加前缀来解决

      [StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential,Pack = 1)]

  2. Nested arrays. 嵌套数组。

    • solved by prefixing array with 通过前缀数组解决

      [MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] [MarshalAs(UnmanagedType.ByValArray,SizeConst = 512)]

Hope it helps. 希望能帮助到你。

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

相关问题 读取 Azure 密钥保管库会引发异常:System.ExecutionEngineException:“引发了‘System.ExecutionEngineException’类型的异常。” - Reading Azure key vault throws exception: System.ExecutionEngineException: 'Exception of type 'System.ExecutionEngineException' was thrown.' 加载嵌入式DLL时引发System.ExecutionEngineException - System.ExecutionEngineException thrown when loading embedded DLL 给定System.ExecutionEngineException的GetMessage() - GetMessage() given an System.ExecutionEngineException DBContext 构造函数中的 System.ExecutionEngineException - System.ExecutionEngineException in DBContext Constructor Windows服务的System.ExecutionEngineException - System.ExecutionEngineException With Windows Service Windows 10设备上的System.ExecutionEngineException - System.ExecutionEngineException on Windows 10 device 仅在调试时才发生System.ExecutionEngineException - System.ExecutionEngineException only when debugging 如何找到 System.ExecutionEngineException 异常的来源 - How to find source of System.ExecutionEngineException Exception 为什么此代码抛出System.ExecutionEngineException - Why this code throws System.ExecutionEngineException 附加到 Revit 过程失败并出现 System.ExecutionEngineException - Attach to Revit process fails with System.ExecutionEngineException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM