I
illegal.prime
Hi all, I'm getting unexpected results when trying to preload
assemblies into an AppDomain I'm creating. Upon creation of the
AppDomain - I attach an AssemblyResolve to both my current AppDomain
and the new AppDomain I create.
I copy all the assemblies/dlls into a new directory and then try
loading them all into the new AppDomain using the following:
private void LoadAssembliesFromDirectory(AppDomain appDomain, string
directory)
{
DirectoryInfo dirInfo = new DirectoryInfo(directory);
foreach (FileInfo fileInfo in dirInfo.GetFiles("*.dll"))
{
try
{
Assembly assembly = Assembly.LoadFrom(fileInfo.FullName);
// Is there a better property we could be handing the Load method
other than the FullName of the assembly?
//appDomain.Load(assembly.FullName);
// The following will hopefully work better
byte[] assemblyByteArray = File.ReadAllBytes(fileInfo.FullName);
Assembly loadedAssembly = appDomain.Load(assemblyByteArray);
}
catch (Exception exception)
{
Trace.WriteLine("LoadAssembliesFromDirectory.LoadAssembliesFromDirectory:
could not load: " + fileInfo.FullName);
Trace.WriteLine("LoadAssembliesFromDirectory.LoadAssembliesFromDirectory:
exception: " + exception.Message);
}
}
}
Oddly enough the AssemblyResolver that ends up getting invoked is the
AssemblyResolver for the current AppDomain - not the new AppDomain
I've created (and whose reference I've passed into the above method).
The above all works and I can start my application using the
AppDomain.ExecuteAssemblyByName. However, it is slower doing the
above (rather than just executing the executable from the command-
line). I can see that the assemblies aren't being loaded in the way
they were before - so not sure why it is slower.
I've heard that remoting is used to pass the assemblies into the new
AppDomain - is that why things are slower? Is there something I could
be doing to make this new approach faster? Or will this approach
always be slower?
Novice
assemblies into an AppDomain I'm creating. Upon creation of the
AppDomain - I attach an AssemblyResolve to both my current AppDomain
and the new AppDomain I create.
I copy all the assemblies/dlls into a new directory and then try
loading them all into the new AppDomain using the following:
private void LoadAssembliesFromDirectory(AppDomain appDomain, string
directory)
{
DirectoryInfo dirInfo = new DirectoryInfo(directory);
foreach (FileInfo fileInfo in dirInfo.GetFiles("*.dll"))
{
try
{
Assembly assembly = Assembly.LoadFrom(fileInfo.FullName);
// Is there a better property we could be handing the Load method
other than the FullName of the assembly?
//appDomain.Load(assembly.FullName);
// The following will hopefully work better
byte[] assemblyByteArray = File.ReadAllBytes(fileInfo.FullName);
Assembly loadedAssembly = appDomain.Load(assemblyByteArray);
}
catch (Exception exception)
{
Trace.WriteLine("LoadAssembliesFromDirectory.LoadAssembliesFromDirectory:
could not load: " + fileInfo.FullName);
Trace.WriteLine("LoadAssembliesFromDirectory.LoadAssembliesFromDirectory:
exception: " + exception.Message);
}
}
}
Oddly enough the AssemblyResolver that ends up getting invoked is the
AssemblyResolver for the current AppDomain - not the new AppDomain
I've created (and whose reference I've passed into the above method).
The above all works and I can start my application using the
AppDomain.ExecuteAssemblyByName. However, it is slower doing the
above (rather than just executing the executable from the command-
line). I can see that the assemblies aren't being loaded in the way
they were before - so not sure why it is slower.
I've heard that remoting is used to pass the assemblies into the new
AppDomain - is that why things are slower? Is there something I could
be doing to make this new approach faster? Or will this approach
always be slower?
Novice