The following situation turned out ...
1) Create a domain in the application.
2) Load it into it via DoCallBack
assembly Assembly.Load(...)
3) From the main domain we get the assemblies previously created and, for example, display their names.
4) We look at what assemblies are in the main domain, and more specifically, there appeared this assembly that we uploaded to another domain.
That is, loading the assembly to another domain, if you use the GetAssemblies
method, the loaded assemblies appear in the main domain, and they are not just transferred there, they are copied - they can be used in both domains.
If you loop the process and watch the memory, you can see that it grows, which means the assemblies are loaded with a new one into memory each time.
The main question is why? How to get rid of the transfer of the assembly in the main domain? There is not even a matter of memory, but the fact that the main domain holds the reference for the assembly and does not allow it to be deleted, for example. And somehow it is necessary to pull out an infa.
class Program { static void Main ( string [ ] args ) { var appDomain = AppDomain.CreateDomain("TestDomain"); appDomain.DoCallBack(LoadModule); var assembly = appDomain.GetAssemblies().Single( t => t.GetName().Name == "TestModule" ); foreach ( var assembly1 in AppDomain.CurrentDomain.GetAssemblies() ) { Console.WriteLine( assembly1.FullName ); } } private static void LoadModule() { Assembly.Load( "TestModule" ); } }
Assembly
objects from the additional domain to the main one, which naturally leads to the loading of the assemblies into the main domain (and not necessarily those that were loaded into the additional one). - PetSerAlGetAssemblyes
call willGetAssemblyes
, I wrote. - anweledigappDomain.GetAssemblies()
, and for each of them callGetName()
. I think it loads your builds in the main domain. - VladD