[IronPython] "GetSearchPaths" does not return the default directories when run in a new Appdomain

mohammad mustaq mustaq2001 at gmail.com
Fri Aug 20 14:15:56 CEST 2010


When I create a python engine in a new Appdomain the "GetSearchPaths"
method return only the current directory. In default domain it returns
"Lib" as well as "Dll" directory in IronPython 2.6.1. Is there a way
to get these search paths while the engine is created in a new

The reason being that the domain manager of the new Appdomain does not
have  any information regarding the "EntryAssembly". Is there a way to
get the data in the Host's domain manager to the new Appdomain's
domain manager. I have provided a code illustrating this.

using System;
using Microsoft.Scripting;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Lifetime;

class Foo
    public static void Main(string[] args)
        AppDomain ad = AppDomain.CreateDomain("foo");
        ScriptEngine engine = Python.CreateEngine(ad);

        ScriptSource code = engine.CreateScriptSourceFromString(@"
import MbrBase
class C(MbrBase):
    def Test_C(self, log):
        print 0
a = C()
", SourceCodeKind.Statements);

        ScriptScope scope = engine.CreateScope();


        Console.WriteLine("Trying to do it... {0}", AppDomain.CurrentDomain.Id);
        MbrBase mbr = (MbrBase)scope.GetVariable("a");

        string isSubClassCode = String.Format("issubclass({0},{1})",
"C", "MbrBase");
        ScriptSource script =

       ICollection<string> paths = engine.GetSearchPaths(); // It
returns only current directory.

        bool result = (bool)script.Execute(scope);

        if (result == true)
            ObjectOperations ops = engine.Operations;
            ObjectHandle subClass = scope.GetVariableHandle("C");
// get back a handle
            ObjectHandle instance = ops.Call(subClass, new
ObjectHandle[0]);  // invoke the handle to create an instance
            mbr = instance.Unwrap() as MbrBase;  // now we know we
have an MBR and we can unwrap it to our local side

            ObjectHandle temp = ops.GetMember(instance, "Test_C");
            object log = null;
            ops.Call(temp, log);


public class MbrBase : MarshalByRefObject
    public virtual void DoItVirtually()
        Console.WriteLine("Did it virtually {0}", AppDomain.CurrentDomain.Id);

    public void DoIt()
        Console.WriteLine("Did it {0}", AppDomain.CurrentDomain.Id);


More information about the Ironpython-users mailing list