I have a WPF application that uses a third-party library to perform a specific task; this library, in one of its methods, executes the statement Assembly.GetEntryAssembly().
If I run the WPF application on debug (by running a .Net exe for testing) the library works properly and Assembly.GetEntryAssembly() returns a reference to the assembly of the executable, but in production I have a different situation that causes me some problems.
In production, the WPF application is integrated with a VB6 application and programs are launched from a VB6 menu using the InteropFormLibrary; in this situation the library raise an exception because Assembly.GetEntryAssembly() returns null (it can’t find the executable associated with the assembly).
My problem is that I can’t change the code of the library because I don’t have the sources available and I found the statement that throws the exception by dll decompiler and analyzing the method that was in the exception.
Now my question is: Is there any way to make sure that the method GetEntryAssembly doesn’t return null? Can I assign or “circumvent” in some way?
The easiest way would be getting the developer of the dll to fix his code to support being hosted in a native (like VB6 or C/C++) process.
That said, if its not possible, you can try to host your .NET side in a separate process, being based on a .NET exe. Since you are doing VB6 interop you’ll probably already be using COM interop, so you could just switch to the out-of-process COM model. This way your .NET components can run inside a .NET exe and have an entry point assembly. I’ve already done that for similar reasons and it worked fine for me.