Download the assembly to the AppDomain child file and release the DLL file

I have a child application domain where I want to load the DLLs into the startup and release files so that someone can delete them.

At startup, I do

Loader al = (Loader)domain.CreateInstanceAndUnwrap(
typeof(Loader).Assembly.FullName,
typeof(Loader).FullName);
al.Load(path)

for the next class.

class Loader : MarshalByRefObject
{
    internal void Load(string path)
    {
        Assembly assembly;
        try
        {
            assembly = Assembly.Load(File.ReadAllBytes(path));
        }
        catch (Exception) { return; }
    }
    internal UseType(string fullyQualifiedTypeName)
    {
         Type userType = Type.GetType(fullyQualifiedTypeName);
    }
}

Later I call UseType, and I get the correct type, but I can no longer delete the file, because it, as it were, the child domain of the application blocked the dll.

Basically I want to cache the assembly file at startup, and then use the calls GetTypeso that the actual dll file is released.

Is it possible to achieve something like this?

+5
source share
1 answer

All Articles