Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic loading working fine, except after the executable is ILMerged

Tags:

c#

vb.net

ilmerge

This is strange.

I have a windows application that dynamically loads DLLs using Reflection.Assembly.LoadFrom(dll_file_name_here).

It works as expected, until I ILMerge the application with another DLL.

So this scenario works fine:

  • MyApp.exe
  • MyAppComponent.dll
  • Plugin.dll

Once I ILMerge MyApp.exe and MyAppComponent.dll resulting in:

  • MyApp.exe
  • Plugin.dll

Calling Reflection.Assembly.LoadFrom("Plugin.dll") seems to load successfully, however once I try to do anything with it eg:

foreach ( typeAsm in Reflection.Assembly.LoadFrom("Plugin.dll")) 

I get an exception "unable to load one or more of the requested types. retrieve the loader exceptions property for more informtion".

The frustrating thing is I can't really debug it, because debugging pre merging works perfectly!

Help?

like image 810
Steve Avatar asked Nov 04 '22 16:11

Steve


1 Answers

My guess is that Plugin.dll references MyApp.exe or MyAppComponent.dll, which are not binary compatible (MyApp.exe) or not there at all (MyApp.dll) after ILMerging.

If that is the case, you shouldn't ILMerge them.

like image 192
Chris Shain Avatar answered Nov 09 '22 08:11

Chris Shain