title: How to host an IronPython engine in a separate AppDomain?
body: <p>I have tried the obvious:</p>
  
  <pre><code>var appDomain = AppDomain.CreateDomain("New Domain");
  var engine = IronPython.Hosting.Python.CreateEngine(appDomain); // boom!
  </code></pre>
  
  <p>But I am getting the following error message: <em>Type is not resolved for member 'Microsoft.Scripting.Hosting.ScriptRuntimeSetup,Microsoft.Scripting, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.</em></p>
  
  <p>Googling for this error has not proved fruitful sofar...</p>
  
  <p><strong>EDIT #1:</strong></p>
  
  <p>I tried to create a minimal reproducing project by copying the relevant stuff to a new Console Application:</p>
  
  <pre><code>using System;
  using Microsoft.Scripting;
  
  namespace PythonHostSamle
  {
      class Program
      {
          static void Main(string[] args)
          {
              AppDomain sandbox = AppDomain.CreateDomain("sandbox");
              var engine = IronPython.Hosting.Python.CreateEngine(sandbox);
              var searchPaths = engine.GetSearchPaths();
              searchPaths.Add(@"C:\Python25\Lib");
              searchPaths.Add(@"C:\RevitPythonShell");
              engine.SetSearchPaths(searchPaths);
              var scope = engine.CreateScope();
              //scope.SetVariable("revit", _application);
              //engine.Runtime.IO.SetOutput(new ScriptOutputStream(_instance),     Encoding.UTF8);
              //engine.Runtime.IO.SetErrorOutput(new ScriptOutputStream(_instance),     Encoding.UTF8);
              var script = engine.CreateScriptSourceFromString("print 'hello, world!'",     SourceCodeKind.Statements);
              script.Execute(scope);
  
              Console.ReadKey();
          }
      }
  }
  </code></pre>
  
  <p>This works as expected!</p>
  
  <p>I am thus left to conclude that the error I am getting is related to <em>one of the lines I commented out</em>: The scope added to the engine contains an object I have little control over - a reference to a plugin host this software is intended to run in (Autodesk Revit Architecture 2010).</p>
  
  <p>Maybe trying to pass that is what is creating the error? </p>
  
  <p>Is there a way to pass a proxy instead? (will have to look up .NET remoting...)</p>
  
  <p><strong>EDIT #2:</strong></p>
  
  <p>I have whittled the problem down to passing an object via the scope that does cannot be proxied to the other AppDomain: All objects added to the scope of an IronPython interpreter running in a different AppDomain will have to be marshaled somehow and must thus either extend <code>MarshalByRefObject</code> or be <code>Serializable</code>.</p>