Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. AppDomain Question

AppDomain Question

Scheduled Pinned Locked Moved C#
questionworkspace
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cobyjone
    wrote on last edited by
    #1

    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?

    T 1 Reply Last reply
    0
    • C cobyjone

      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?

      T Offline
      T Offline
      turbochimp
      wrote on last edited by
      #2

      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...’

      C 1 Reply Last reply
      0
      • T turbochimp

        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...’

        C Offline
        C Offline
        cobyjone
        wrote on last edited by
        #3

        Yes, IInterface (whatever interface it may be) is in AssemblyC, which both AssemblyA and AssemblyB reference AssemblyC. But no assembly references AssemblyB.

        T L 2 Replies Last reply
        0
        • C cobyjone

          Yes, IInterface (whatever interface it may be) is in AssemblyC, which both AssemblyA and AssemblyB reference AssemblyC. But no assembly references AssemblyB.

          T Offline
          T Offline
          turbochimp
          wrote on last edited by
          #4

          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...’

          1 Reply Last reply
          0
          • C cobyjone

            Yes, IInterface (whatever interface it may be) is in AssemblyC, which both AssemblyA and AssemblyB reference AssemblyC. But no assembly references AssemblyB.

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups