How to load an application with dll from memory in AppDomain and execute it?

I have several threads with assembly and used DLLs. How can I upload them to AppDomain and complete the main build? I would prefer not to save the files to disk if this can be avoided.

+3
source share
1 answer

You can use 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 thing to serve the 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 into your program will end here, so you may need to create a caching mechanism to store type information

+1

Source: https://habr.com/ru/post/1758451/


All Articles