AppDomain Question
-
I am trying to have assembly A load assembly B into a seperate domain. It's odd because when I load the assembly into the second AppDomain, it is also loaded into the default domain. So, when I unload the second AppDomain, it doesn't actually unload the assembly. Am I doing something wrong here: AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = AppDomain.Current.SetupInformation.ApplicationBase; setup.ApplicationName = "Test"; AppDomain domain = AppDomain.CreateDomain("NewDomain", null, setup); IInterface i = (IInterface)domain.CreateInstanceFromAndUnwrap("AssemblyB.dll", "AssemblyB.Interface"); If I run AppDomain.Current.GetAssemblies() to get the loaded assemblies before I run this code, it does not show AssemblyB loaded. If I run it after, it is loaded in the default domain. If I unload the second domain, it is still loaded in the default domain. No other project in the solution is dependent on AssemblyB, so it shouldn't be loading it into the default domain. Any ideas?
-
I am trying to have assembly A load assembly B into a seperate domain. It's odd because when I load the assembly into the second AppDomain, it is also loaded into the default domain. So, when I unload the second AppDomain, it doesn't actually unload the assembly. Am I doing something wrong here: AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = AppDomain.Current.SetupInformation.ApplicationBase; setup.ApplicationName = "Test"; AppDomain domain = AppDomain.CreateDomain("NewDomain", null, setup); IInterface i = (IInterface)domain.CreateInstanceFromAndUnwrap("AssemblyB.dll", "AssemblyB.Interface"); If I run AppDomain.Current.GetAssemblies() to get the loaded assemblies before I run this code, it does not show AssemblyB loaded. If I run it after, it is loaded in the default domain. If I unload the second domain, it is still loaded in the default domain. No other project in the solution is dependent on AssemblyB, so it shouldn't be loading it into the default domain. Any ideas?
Are the two types in separate projects?
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
-
Are the two types in separate projects?
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
-
Yes, IInterface (whatever interface it may be) is in AssemblyC, which both AssemblyA and AssemblyB reference AssemblyC. But no assembly references AssemblyB.
Okay. After going in many small circles due to encroaching fatigue, I found this article[^]. Its focus is specifically on plug-ins, but in general it's about making assembly loading and unloading in remote AppDomains workable. I made up a little test code using the technique, and it works dandy. The key is to set up the second (remote) AppDomain to use a shadow cache, so you have to use an AppDomainSetup, which has some really cruddy documentation (took me 20 minutes playing with it even after reading the article above to make sense of it). Ultimately, though, I was able to load my interface type into the remote AppDomain without it appearing in my primary AppDomain, and of course I was able to unload it with no problems. Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
-
Yes, IInterface (whatever interface it may be) is in AssemblyC, which both AssemblyA and AssemblyB reference AssemblyC. But no assembly references AssemblyB.
Also try my PluginManager article, had to deal with the same issues. IIRC I had to create proxies (transparent cross domain objects) to prevent types jumping domain boundries. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots