简体   繁体   中英

System.ExecutionEngineException thrown when loading embedded DLL

A customer reported a problem in which one of my programs would crash when they tried to run it. They provided a dump file generated during the crash. The dump file showed that the problem was a System.ExecutionEngineException being thrown when I was extracting a DLL embedded as a resource in the program.

The code in question is:

public FrontEnd()
{
    AppDomain.CurrentDomain.AssemblyResolve += (sender, args2) =>
    {
        var resourceName = new AssemblyName(args2.Name).Name + ".dll";
        var resource = Array.Find(this.GetType().Assembly.GetManifestResourceNames(), element => element.EndsWith(resourceName, StringComparison.CurrentCulture));

        using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
        {
            var assemblyData = new byte[stream.Length];
            stream.Read(assemblyData, 0, assemblyData.Length);
            return Assembly.Load(assemblyData);
        }
    };

    this.InitializeComponent();
}

I am using an approach described on this website , and have had no problems with it until now.

The exception is thrown on the GetManifestResourceStream() line.

For information this code has worked on many PCs around the world for several months, but not for this customer.

Running the program in administrator mode made no difference.

Both the program and the DLL are written in C# (4.0).

I have tried disabling concurrent garbage collection as suggested in this stackoverflow post .

One of my colleagues asked the customer to try another program that uses the same technique, and it had the same problem.

I have worked around this for now by commenting out this code. But I would like to know: why is this happening? How do I fix it properly? Is there a better way to embed DLLs? [FYI, I started doing this after several customers had issues with copying the program and forgetting to also copy the then-separate DLLs].

The answer seems to be related to @StuartLC's comment about the .Net framework. The problem has since occurred several times, always on PCs running non-English versions of .Net. When the users upgrade to .Net 4.5.1 ( https://www.microsoft.com/en-in/download/details.aspx?id=40779 ) the problem is resolved.

FYI, this does not seem to be constrained to a particular language.

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