Reputation: 1140
I have several streams with an assembly and its used dlls. How can I load them into an AppDomain and execute the main assembly? I'd rather not save the files to disk if it can be avoided.
Upvotes: 3
Views: 843
Reputation: 2119
You can use obtain the assembly through the following mechanism.
Assembly myAssembly = Assembly.Load(<your raw file stream>);
You can register for the following event and handle the same to serve requested types coming from your custom assemblies:
AppDomain.CurrentDomain.TypeResolve += new ResolveEventHandler(CurrentDomain_TypeResolve);
static Assembly CurrentDomain_TypeResolve(object sender, ResolveEventArgs args)
{
Type resolvedType = myAssembly.GetType( args.Name, false);
}
Unfortunately any type loaded in your program would end up here, so you might want to build in some caching mechanism to store type info
Upvotes: 1