[IronPython] "GetSearchPaths" does not return the default directories when run in a new Appdomain
Dino Viehland
dinov at microsoft.com
Fri Aug 20 20:28:51 CEST 2010
You can manually provide the search paths:
Dictionary<string, object> options = new Dictionary<string, object>();
options["SearchPaths"] = new [] { ".", "C:\\SomeDirectory\\DLLs", "C:\\SomeDirectory\\Libs" };
ScriptEngine engine = Python.CreateEngine(ad, options);
I don't know of a way to set the entry assembly other than via starting an .EXE
Normally.
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of mohammad mustaq
> Sent: Friday, August 20, 2010 5:16 AM
> To: Discussion of IronPython
> Subject: [IronPython] "GetSearchPaths" does not return the default directories
> when run in a new Appdomain
>
> Hi,
>
> 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
> Appdomain.
>
> 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);
> engine.Runtime.LoadAssembly(typeof(MbrBase).Assembly);
>
> ScriptSource code = engine.CreateScriptSourceFromString(@"
> import MbrBase
> class C(MbrBase):
> def Test_C(self, log):
> print 0
> a = C()
> ", SourceCodeKind.Statements);
>
> ScriptScope scope = engine.CreateScope();
>
> code.Execute(scope);
>
> 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 =
> engine.CreateScriptSourceFromString(isSubClassCode,
> SourceCodeKind.Expression);
>
> 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);
> }
>
> mbr.DoItVirtually();
> mbr.DoIt();
> Console.ReadKey();
> }
> }
>
> 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);
> }
> }
>
> thanks,
> Mustaq
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list