Here's an example code:

var setup = new AppDomainSetup(); setup.PrivateBinPath = $"{Directory.GetCurrentDirectory()}\\Libs"; var appDomain = AppDomain.CreateDomain( "имя домСна", null, setup ); appDomain.DoCallBack ( AssemblyLoad ); 

An example of a method in Kalbek:

 private static void AssemblyLoad() { var assembly = Assembly.Load( "Test" ); var type = assembly.GetTypes().Single( t => typeof( НуТныйВип).IsAssignableFrom( t ) ); Console.WriteLine( type.FullName ); _typeName = type.FullName; } 

The _typeName variable _typeName also static and remains empty. If you make the method not static, then the callback domain will cause an error. How to find out the name of the required type?

    1 answer 1

    Create an additional class that inherits from MarshalByRefObject and drag AssemblyLoad , _typeName into it, making them non-static.

    For unknown reasons, DoCallBack does not work (most likely, it pulls the assembly into the current domain), but CreateInstanceAndUnwrap works:

     class Test : MarshalByRefObject { private Type _typeName; public void AssemblyLoad() { var assembly = Assembly.Load( "Test" ); var type = assembly.GetTypes().Single( t => typeof( НуТныйВип).IsAssignableFrom( t ) ); Console.WriteLine( type.FullName ); _typeName = type.FullName; } } // ... var setup = new AppDomainSetup { PrivateBinPath = "Libs" }; var appDomain = AppDomain.CreateDomain("имя Π΄ΠΎΠΌΠ΅Π½Π°", null, setup); var test = (Test)appDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(Test).FullName); test.AssemblyLoad(); 

    This will cause the following problem: if you try to access test._typeName in the current domain, this will test._typeName in loading the Test assembly into it. Since the private path for the current domain is not registered, a FileNotFoundException exception will FileNotFoundException . You will either have to configure the private path for the current domain, or work with the loaded assembly exclusively within the second domain, passing only the results of its work to the outside.

    • Yes, as long as the assembly is in the same folder as the application, then everything is fine. But as soon as you PrivateBinPath , the non-static method throws an error. - anweledig
    • @anweledig: What kind of error? (If something about assembly loading, then what's in the fusion log?) - VladD
    • System.IO.FileNotFoundException : Π”ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ свСдСния: НС ΡƒΠ΄Π°Π»ΠΎΡΡŒ Π·Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚ΡŒ Ρ„Π°ΠΉΠ» ΠΈΠ»ΠΈ сборку "Test" Π»ΠΈΠ±ΠΎ ΠΎΠ΄Π½Ρƒ ΠΈΠ· ΠΈΡ… зависимостСй. НС удаСтся Π½Π°ΠΉΡ‚ΠΈ ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΉ Ρ„Π°ΠΉΠ». Π”ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ свСдСния: НС ΡƒΠ΄Π°Π»ΠΎΡΡŒ Π·Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚ΡŒ Ρ„Π°ΠΉΠ» ΠΈΠ»ΠΈ сборку "Test" Π»ΠΈΠ±ΠΎ ΠΎΠ΄Π½Ρƒ ΠΈΠ· ΠΈΡ… зависимостСй. НС удаСтся Π½Π°ΠΉΡ‚ΠΈ ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΉ Ρ„Π°ΠΉΠ». From what has changed - the location of the file and an indication of this in the setup and the actual static method is converted into a non-static one, everything works fine with a static one. - anweledig
    • @anweledig updated - kmv
    • it's sad, thanks for the reply) - anweledig