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 LoadAssembliesF romDirectory(Ap pDomain appDomain, string
directory)
{
DirectoryInfo dirInfo = new DirectoryInfo(d irectory);
foreach (FileInfo fileInfo in dirInfo.GetFile s("*.dll"))
{
try
{
Assembly assembly = Assembly.LoadFr om(fileInfo.Ful lName);
// Is there a better property we could be handing the Load method
other than the FullName of the assembly?
//appDomain.Load( assembly.FullNa me);
// The following will hopefully work better
byte[] assemblyByteArr ay = File.ReadAllByt es(fileInfo.Ful lName);
Assembly loadedAssembly = appDomain.Load( assemblyByteArr ay);
}
catch (Exception exception)
{
Trace.WriteLine ("LoadAssemblie sFromDirectory. LoadAssembliesF romDirectory:
could not load: " + fileInfo.FullNa me);
Trace.WriteLine ("LoadAssemblie sFromDirectory. LoadAssembliesF romDirectory:
exception: " + exception.Messa ge);
}
}
}
Oddly enough the AssemblyResolve r that ends up getting invoked is the
AssemblyResolve r 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.Execu teAssemblyByNam e. 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 LoadAssembliesF romDirectory(Ap pDomain appDomain, string
directory)
{
DirectoryInfo dirInfo = new DirectoryInfo(d irectory);
foreach (FileInfo fileInfo in dirInfo.GetFile s("*.dll"))
{
try
{
Assembly assembly = Assembly.LoadFr om(fileInfo.Ful lName);
// Is there a better property we could be handing the Load method
other than the FullName of the assembly?
//appDomain.Load( assembly.FullNa me);
// The following will hopefully work better
byte[] assemblyByteArr ay = File.ReadAllByt es(fileInfo.Ful lName);
Assembly loadedAssembly = appDomain.Load( assemblyByteArr ay);
}
catch (Exception exception)
{
Trace.WriteLine ("LoadAssemblie sFromDirectory. LoadAssembliesF romDirectory:
could not load: " + fileInfo.FullNa me);
Trace.WriteLine ("LoadAssemblie sFromDirectory. LoadAssembliesF romDirectory:
exception: " + exception.Messa ge);
}
}
}
Oddly enough the AssemblyResolve r that ends up getting invoked is the
AssemblyResolve r 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.Execu teAssemblyByNam e. 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
Comment