Help needed when unloading .DLL from AppDomain - still not working even with ShadowCopy

I am trying to do the following. Appendix A is a "mother app." He stays open. Appendix B is just .DLL, where I write some classes derived from the interface specified in Appendix A.

Then from App A, I will “import” classes from application B and run the methods in them. I want to be able to dynamically change application B (change the code and recompile) and use the new code in application A.

I have a post-compile command in application B that copies a new .DLL to the directory of application A. Appendix A creates a new AppDomain and uses ShadowCopying. I thought this would be enough, but when I try to recompile and copy the new .DLL of application B., it says that the file is in use and cannot be overwritten.

Here is the code that I have at the moment:

Appendix A (TestServer in code):

namespace TestServer
{
    public interface IRunnable
    {
        void Run();        
    }

    class Program
    {        
        static void Main(string[] args)
        {
            AppDomainSetup setup = new AppDomainSetup();
            setup.ApplicationName = "DemoApp";
            setup.ApplicationBase = Environment.CurrentDirectory;
            setup.ShadowCopyDirectories = Environment.CurrentDirectory;
            setup.ShadowCopyFiles = "true";
            int _domain = 1;

            while (true)
            {
                string typeName = Console.ReadLine();

            AppDomain appDomain = AppDomain.CreateDomain("DemoDomain" + _domain, null, setup);

            IRunnable runner = appDomain.CreateInstanceFromAndUnwrap("TestClient.dll", typeName) as IRunnable;

            runner.Run();

            AppDomain.Unload(appDomain);
            _domain++;
            }
        }   
    }   
}

Appendix B (TestClient in code):

namespace TestClient
{    
    public class TestRunner : TestServer.IRunnable
    {
        public void Run()
        {
            Console.WriteLine("RUNNING");
        }
    }

    public class Bob : TestServer.IRunnable
    {
        public void Run()
        {
            Console.WriteLine("BOB");
        }
    }
}

I read that if you use material from other application domains, these application domains can automatically download .DLL or something in that direction. In this case, I fear that using the interface will cause the underlying AppDomain to load .DLL, thereby blocking it.

How can I solve this problem / is there a more efficient setup?

. , .

+3
3

- AppDomain, . . - : AppDomain

100%, , , ,

, DomainLifetimeHook. , Start Stop AppDomain, AppDomainExpander. Expander - , , Create .

+3

, :

Type type = assm.GetType("TestClient." + typeName);

AppDomain A, , AppDomain B.dll

flq .

0

appdomain, ObjectHandle. .

0

All Articles