[IronPython] No module named System
Hello Sticky
hellosticky at gmail.com
Wed Sep 3 00:53:03 CEST 2008
Hi, I'm dynamically loading a python assembly built through pyc.py
into a partially trusted AppDomain. First, the exception, and after
that follows the code I'm using. The question is: how do I need to add
a reference to System.dll -- through runtime.LoadAssembly,
clr.AddReference, or both?
IronPython.Runtime.Exceptions.ImportException: "No module named System"
at IronPython.Runtime.Builtin.__import__(CodeContext context,
String name, Object globals, Object locals, Object fromlist, Int32
level)
at IronPython.Runtime.Builtin.__import__(CodeContext context,
String name, Object globals, Object locals, Object fromlist)
at _stub_$20##20(Closure , CallSite , CodeContext , Object , String
, IAttributesCollection , IAttributesCollection , PythonTuple )
... long stack trace
Loading code:
Assembly assembly = Assembly.Load(AssemblyName);
ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));
ScriptRuntime runtime = new ScriptRuntime(setup);
runtime.LoadAssembly(assembly);
runtime.IO.SetOutput(ms, writer);
ScriptEngine engine = runtime.GetEngine(GetEngineName());
ScriptScope scope = engine.CreateScope();
string code = string.Format(@"import clr
clr.AddReference(""{0}"")
import {1}
",
AssemblyName,
AssemblyType.Replace(".py", "")
);
ScriptSource source = engine.CreateScriptSourceFromString(
code,
SourceCodeKind.Statements
);
source.Execute(scope);
Thanks,
More information about the Ironpython-users
mailing list