Closed moh-hassan closed 5 years ago
Sorry, but that won't work. ILMerge works by taking each member of the input assemblies and reparents them so that they belong to the merged assembly. For instance, if there is a type T in an assembly A, then it's fully-qualified name is "[A]T" (using the format that you'll see if you use ildasm to open an assembly). If you use ILMerge to merge assembly A into the merged assembly M, then the type T has the fully-qualified name "[M]T". It is a totally distinct type (to .NET) from [A]T.
Hope that is clear. Let me know if you need any more help.
Thanks for reply. Is there other way to resolve the plugin problem?
Sorry, not that I am aware of. The assembly you are trying to load at runtime was compiled against "mylib" and so that assembly must be present in order to load/run the assembly.
Kindly, mylib is merged in the exe,
So, should i exclude that library for merging? Do I move the types/interfaces used by the plugin in a separate library and exclude it from merging.? Is there something can control the feasibility of some types like you do in internalize option? may be future feature.
Well, yes, if you don't merge mylib.dll into the merged assembly then your console application will still have a dependence on it. So to run your application mylib.dll will have to be found by the .NET Runtime and so will be available when the plugin executes and also needs it. I don't see any feature that will ever make your scenario work: you would have to re-compile the plugin so that it references the merged assembly instead of mylib.dll.
Thanks @mike-barnett. I will take into account this constraint for using external plugin(s).
Here is an example implementation, you need to prescribe with the list of libraries with your hands. Ideally, ILMerge does it all by itself.
[assembly: AutoResolveMergedAssembliesAttribute("ILMergeDynamic.BaseModule")]
[assembly: AutoResolveMergedAssembliesAttribute("Lobster.Home.DependencyInjection.ServiceTypeProvider")]
MainAssembly.Main()
{
AutoResolverInstaller.EnsureInstalled()
}
I merged a Console application that reference a class libray mylib.dll in net45 with ILMerge utility.
The Console application load plugin(s) at runtime that implement an Interface.
The plugin reference the same class library mylib.dll that is used by console.exe
If I run the console application without merge, it can load the plugin successfully.
The merge command
But When merging the console application with all its dependencies using ILMerge, the plugin can't be loaded and raise an exception:
The question: As the assemply mylib.dll is merged in exe, is there a way to extract that assemply at runtime and load it using the event
AppDomain.CurrentDomain.AssemblyResolve