title: How to send nonserializable objects as arguments to a proxy method. MarshalByRefObject wrapper?
body: <p>I'm am currently revising a plugin architecture so that it utilizes AppDomains. The main difference between my plugins and the many examples I have found online is that instead of the plugin running and sending its results back to the main application, my main application is the one sending information to the plugin.</p>
  
  <p>As it currently stands, I create an instance of the loader in a separate AppDomain. It then does all your normal initialization such as loading the plugin assembly. As this point, I then use the proxy of the loader to call the methods that send the data from the main application to the new AppDomain.</p>
  
  <p>My problem occurs when I am attempting to call a method which has an argument type that is not serializable, and which does not derive from MarshalByRefObject.</p>
  
  <p>Since these types are from 3rd party code, and the plugins expect to receive them, I cannot seem to find a way do this. After finding this question ( <a href="https://stackoverflow.com/q/313243/1489214">How to solve &quot;Must be MarshalByRefObject&quot; in a good but multiple-inheritance amputated language like C#?</a> ), I was thinking about creating some sort of wrapper. My drawback here is that I simply cant figure out a way to make one without modifying the 3rd party code.</p>
  
  <p>Here is an example of my issue:</p>
  
  <pre><code>// Cant modify this class
  class ThirdPartyClass
  {
      // The properties are also 3rd party and nonserializable. These are accessed by the plugins.
      public AnotherClass Property1{ get; set; }
      public AnotherClass Property2{ get; set; }
  
      public ThirdPartyClass(){}
  }
  
  class Loader : MarshalByRefObject
  {
      private Plugin plugin;
  
      public Loader()
      {
          Assembly pluginAssembly = Assembly.LoadFrom("Full/Assembly/Path");
          plugin = pluginAssembly.CreateInstance("Full.Plugin.Name") as Plugin;
      }
  
      public void DoSomething(ThirdPartyClass o)
      {
          ...
          plugin.DoSomethingElse(o);
      }
  }
  
  class PluginManager
  {
      void Main(ThirdPartyClass o)
      {
          AppDomain pluginAppDomain = AppDomain.CreateDomain("Plugin AppDomain");
          Loader loader = pluginAppDomain.CreateInstanceFromAndUnwrap("Full/Loader/Path", "Full.Loader.Name") as Loader;
  
          // This is where I would have a problem.
          loader.DoSomething(o);
      }
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>