1

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].

Community
  • 1
  • 1
Journeyman
  • 95
  • 9
  • This post here tries to sum up [some of the causes](http://stackoverflow.com/questions/967044/system-executionengineexception-failure). Other than bugs in early .Net Framework (which should be well fixed through patches), this often occurs at the interface with badly behaved Unmanaged (PInvoke / COM) code. – StuartLC Apr 21 '15 at 12:11
  • 1
    An isolated failure like this is not your problem, the customer needs to re-image his machine. Your time is best spent creating a proper installer for your program, I'd say. – Hans Passant Apr 21 '15 at 12:29
  • Thanks @StuartLC. That's actually the post I linked to from the question, so I've had a look at it, but didn't manage to identify the root cause in my case. – Journeyman Apr 23 '15 at 11:44
  • @HansPassant: since I posted this question the same thing has actually happened with two other customers. I don't know how this can have been dormant for months and then suddenly gets reported several times in a few days. Anyway, it's a thing, and I have to deal with it. Your suggestion about creating an installer is definitely something I'll be looking at, thanks for that. – Journeyman Apr 23 '15 at 11:46

1 Answers1

0

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.

Journeyman
  • 95
  • 9