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.
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
加载中,请稍侯......
精彩评论