Loading the Aspose.PDF.dll within the AppDomian.AssemblyResolve event causes "ghost" Assemblies as soon as some components of said dll are called inside another dll.
The problem here is that the Registration of the Aspose.PDF.dll does not work because of those "ghost" assemblies that are created or atleast that is what I think that the problem is.
So basically: Why are there those "ghost" assemblies?
First off, I got the following components: -Console application (Main) -Class library (MyDll) -3rd party dll in this case Aspose.PDF.dll
Main has no reference to MyDll aswell as no reference to the 3rd party dll. MyDll has a reference to a specific version of the 3rd party dll.
I want to load the correct version of the Aspose.PDF.dll from a remote location into the AppDomain corresponding of which version MyDll asks for.
To achieve this I subscribe to the AppDomain.AssemblyResolve
event.
If MyDll is called and asks for an assembly that the clr can't find I load the corresponding dll with LoadFrom.
This works well so far but while overwatching the loaded assemblies, that I get when I call AppDomain.CurrentDomain.GetAssemblies()
, I noticed that there are some assemblies that have a weird name but seeme to be Aspose.PDF assemblies (the public key is the same). Those only appear after certain methods in MyDll are called. All these methods contain Aspose.PDF method calls.
I created an Example to demonstrate this Issue. First the Main console application.
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad;
Assembly myAssembly = Assembly.LoadFile(@"FullPathToMyDll\MyDll.dll");
Type myType = myAssembly.GetType("myDll.Class1");
var myTypeInstance = Activator.CreateInstance(myType);
myType.InvokeMember("DoAction", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, myTypeInstance, null);
Console.ReadLine();
}
private static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
StringBuilder stb = new StringBuilder();
stb.AppendLine(new string('-', 20));
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
stb.AppendLine(assembly.FullName);
}
stb.AppendLine(new string('-', 20));
Console.WriteLine(stb.ToString());
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var nameSplitted = args.Name.Split(',');
Assembly assemblyToReturn = null;
if(args.Name.Contains("19.2.0.0"))
assemblyToReturn = Assembly.LoadFrom(@"FullPathToDll\Apsose_19.2\Aspose.PDF.dll");
if (args.Name.Contains("19.6.0.0"))
assemblyToReturn = Assembly.LoadFrom(@"FullPathToDll\Apsose_19.6\Aspose.PDF.dll");
return assemblyToReturn;
}
}
MyDll.dll:
public class Class1
{
public Class1()
{
Console.WriteLine(Aspose.Pdf.BuildVersionInfo.FileVersion);
Console.WriteLine(Aspose.Pdf.BuildVersionInfo.Product);
Console.WriteLine(Aspose.Pdf.BuildVersionInfo.AssemblyVersion);
}
public void DoAction()
{
// Part of the 3rd party dll
Document doc = new Document();
// After the following line the "ghost assemblies appear"
bool licensed = Document.IsLicensed;
Console.WriteLine(doc.GetType().Assembly.FullName);
}
}
Image of loaded "ghost assemblies" I wouldn't suppose there should be those "ghost" assemblies and I think they lead to a problem with the registration of the 3rd party dll (which is not included in this example).
This is my first question on stackoverflow so please give me any feedback regarding how I asked my questrion and what I could do better.