[IronPython] No module named System

Curt Hagenlocher curt at hagenlocher.org
Wed Sep 3 01:15:55 CEST 2008


clr.AddReference ultimately calls ScriptRuntime.LoadAssembly under the
covers -- so the two can be considered equivalent.  If you want to call from
the host, use LoadAssembly and if you want to call from within Python, use
AddReference.

On Tue, Sep 2, 2008 at 3:53 PM, Hello Sticky <hellosticky at gmail.com> wrote:

> 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,
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080902/33dbc667/attachment.html>


More information about the Ironpython-users mailing list