title: MAF (System.Addin) property of serializable type in contract?
body: <p>We are testing the MAF addin to use as our addin framework. But we get stuck at a basic issue. Can we use serializable types as IContract parameters?</p>
  
  <p>Both the contract and the parameter type is defined in the same assembly:</p>
  
  <pre class="lang-cs prettyprint-override"><code>    public interface IHostContract : IContract
      {
          void SetCurrent(TheValue tagValue);   // does not work
          void SetCurrentSimple(double value);  // works fine
      }
  
      [Serializable]
      public sealed class TheValue
      {
         public int Id { get; set; }
  
         public double Value { get; set; }
      }
  </code></pre>
  
  <p>We are able to get everything up and running. Calling the SetCurrent results in an exception:
      AppDomainUnloadedException : </p>
  
  <pre><code>The application domain in which the thread was running has been unloaded.
  
  Server stack trace: 
     at System.Threading.Thread.InternalCrossContextCallback(Context ctx, IntPtr ctxID, Int32 appDomainID, InternalCrossContextDelegate ftnToCall, Object[] args)
     at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage&amp; smuggledMrm)
     at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg)
  
  Exception rethrown at [0]: 
  </code></pre>
  
  <p>Loading and running of plugins:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public void Run(string PluginFolder)
  {
      AddInStore.Rebuild(PluginFolder);
      Collection&lt;AddInToken&gt; tokens = AddInStore.FindAddIns(typeof(Plugins.IPlugin), PluginFolder);
  
      foreach (var token in tokens)
      {
          Console.WriteLine("Found addin: " + token.Name + " v" + token.Version);
          try
          {
              var plugin = token.Activate&lt;Plugins.IPlugin&gt;(AddInSecurityLevel.FullTrust);
              plugin.PluginHost = this;
              plugin.Start();
              plugin.Stop();
          }
          catch (Exception exception)
          {
              Console.WriteLine("Error starting plugin: " + exception.Message);
          }
      }
  }
  </code></pre>
  
  <p>Plugin:</p>
  
  <pre><code>[System.AddIn.AddIn("Plugin1", Version = "1.0.0")]
  public class Plugin1 : IPlugin
  {
      private int started;
  
      public Plugin1()
      {
          Console.WriteLine("Plugin 1 created");
      }
  
      public void Start()
      {
          Console.WriteLine("Plugin 1 started: {0}", started);
          started++;
  
          var tagValue = new TheValue { Id = 1, Value = 4.32 };
          PluginHost.SetCurrent(tagValue);
      }
  
      public void Stop()
      {
          Console.WriteLine("Plugin 1 stopped");
      }
  
      public IPluginHost PluginHost { get; set; }
  }
  </code></pre>