开发者

Dynamic loading working fine, except after the executable is ILMerged

开发者 https://www.devze.com 2023-03-28 03:10 出处:网络
This is strange. I have a windows application that dynamically loads DLLs using Reflection.Assembly.LoadFrom(dll_file_name_here).

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消