title: how the data in different AppDomains are organised and how can I access them across the domains
body: <p>Hi I have application that consist of some "kernel" and modules that are dynamically loaded to own AppDomain and unloaded as needed. But I don't understand one thing. I will post a simple code that is similar to what I have.</p>
  
  <p>There is "interface" a class that contains lot of virtual hooks and properties and some own functions:</p>
  
  <pre><code>[Serializable()]
  public abstract class Module : MarshalByRefObject
  {
      public static List&lt;Module&gt; module = new List&lt;Module&gt;();
      public string Name = "";
      public string Version = "unknown";
      public DateTime Date = DateTime.Now;
  
      Module()
      {
          lock(module)
          {
              module.Add(this);
          }
      }
  
      ~Module()
      {
          Exit();
          lock (module)
          {
              if (module.Contains(this))
              {
                  module.Remove(this);
              }
          }
          core.Log("Module was unloaded: " + this.Name);
      }
  
      public virtual void Hook1()
      {
        // by default ignore
      }
  }
  </code></pre>
  
  <p>each module is a new project that is referenced to core and creates a new class that is inherited from Module and extends the "kernel". Some events are hooked in a way that I go in a loop through Module.module List that is supposed to contain all existing loaded instances and call the respective hook in that one. This works fine if I am in one AppDomain. But if I use a separate AppDomain for module it seems that the memory of original Domain get copied to new domain and when I call the constructor of new instance, it doesn't insert itself to static array in Module.module of original domain, but it insert itself to Module.module in a new domain. That means, in core I still have 0 modules in Module.module. I managed to fix this by creating another function that register module instead of what I had in constructor. But still it happens that sometimes I access the memory in original domain and sometime the memory in new domain of module. This causes troubles. How can I make it sure that I always access the same memory from kernel and from module as well?</p>
  
  <p>Example of what I need to do is:</p>
  
  <ul>
  <li>Pass pointer to instance of a class which is in memory of AppDomain A to a hook of module living in AppDomain B</li>
  <li>let the module change something in that class (in memory of domain A, not in B)</li>
  </ul>