Arjan
Arjan

Reputation: 41

Mixed mode .NET 4.0 assembly refuses to load in Windows 10 Pro but loads fine in Windows 10 Home

I have a Visual Studio 2012 Solution with a WPF project that provides a GUI for a mixed mode DLL project (let's call it xxxxx.DLL) in that same solution.

Now on Windows 10 Home the WPF project loads fine (both inside and outside of the VS2012 debugger) and there is no trouble loading the mixed mode DLL. But if I try this on Windows 10 Pro (outside any debugger) I get the following error:

System.IO.FileNotFoundException: Could not load file or assembly 'xxxxxx.DLL' or one of its dependencies. The specified module could not be found.

I already know the error message is wrong and misleading because I added the following test code to my application that is executed before the DLL gets loaded:

        var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
        var executingFolder = System.IO.Path.GetDirectoryName(executingAssembly.Location);
        var DLLpath = System.IO.Path.Combine(executingFolder, "xxxxxx.DLL");
        System.Windows.MessageBox.Show("Calling ReflectionOnlyLoadFrom(" + DLLpath + ")");
        try
            {
            System.Reflection.Assembly.ReflectionOnlyLoadFrom(DLLpath);
            }
        catch (Exception dlle)
            {
            System.Windows.MessageBox.Show(dlle.ToString(), "ELWAVE Pro - ChartWindow constructor");
            }
        System.Windows.MessageBox.Show("Returned from ReflectionOnlyLoadFrom");


        System.Windows.MessageBox.Show("Calling LoadFile(" + DLLpath + ")");
        try
            {
            //System.Reflection.Assembly.UnsafeLoadFrom(DLLpath);
            var assembly = System.Reflection.Assembly.LoadFile(DLLpath);
            }
        catch (Exception dlle)
            {
            System.Windows.MessageBox.Show(dlle.ToString(), "ELWAVE Pro - ChartWindow constructor");
            }
        System.Windows.MessageBox.Show("Returned from LoadFile");

The call to ReflectionOnlyLoadFrom succeeds but the call to LoadFile (or UnsafeLoadFrom) produces the same 'file not found' error.

I checked with .NET Reflector if I was missing any dependencies on the Windows 10 Pro system but that does not appear to be the case.

I also checked with Fusion++ (easier to use version of fuslogvw.exe) and it shows the following with regard to this DLL:

WRN: No matching native image found.
LOG: IL assembly loaded from C:\Users\xxxxxx\Documents\xxxxxx\xxxxxx.dll.

I don't know if this is significant though, this warning also shows for WpfToolkit and WPFToolkit.Extended and System.Drawing.

From all this it appears that the DLL can be found, but that for some reason the CLR runtime refuses to load it. Since this behavior is different on Windows 10 Home (where it does load) and Windows 10 Pro (where it does NOT load and produces this error), I'm wondering if there are some default security policies on Windows 10 Pro that might cause this.

Incidentally I have tried creating a small test project that has this problem but that does not appear to be as trivial as I had hoped. A very simply 5 line mixed-mode assembly did load fine on Windows 10 Pro so there is more going on.

I forgot to mention: both projects target .NET Platform Framework 4.0. The GUI used to be on 4.5 but I changed it back to 4.0 just in case this contributed to the problem.

Also, the DLL does not have a strong name right now (ie. it's not signed). Could that be a problem specifically on Windows 10 Pro?

If anybody has any suggestions on how to further investigate and especially solve this problem I would be very grateful. I hope to be able to avoid stepping through the code with ILSpy dnSpy and even with that I'm not sure I will be able to find a solution.

Added: I forgot to mention that for the WPF GUI app the Platform target is x86 and the mixed mode DLL is also 32 bit.

Upvotes: 0

Views: 51

Answers (0)

Related Questions