<div dir="ltr">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.<br>
<br>
<div class="gmail_quote">On Tue, Sep 2, 2008 at 3:53 PM, Hello Sticky <span dir="ltr"><<a href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Hi, I'm dynamically loading a python assembly built through pyc.py<br>into a partially trusted AppDomain. First, the exception, and after<br>
that follows the code I'm using. The question is: how do I need to add<br>a reference to System.dll -- through runtime.LoadAssembly,<br>clr.AddReference, or both?<br><br>IronPython.Runtime.Exceptions.ImportException: "No module named System"<br>
at IronPython.Runtime.Builtin.__import__(CodeContext context,<br>String name, Object globals, Object locals, Object fromlist, Int32<br>level)<br> at IronPython.Runtime.Builtin.__import__(CodeContext context,<br>String name, Object globals, Object locals, Object fromlist)<br>
at _stub_$20##20(Closure , CallSite , CodeContext , Object , String<br>, IAttributesCollection , IAttributesCollection , PythonTuple )<br>... long stack trace<br><br>Loading code:<br><br>Assembly assembly = Assembly.Load(AssemblyName);<br>
ScriptRuntimeSetup setup = new ScriptRuntimeSetup();<br> setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));<br> ScriptRuntime runtime = new ScriptRuntime(setup);<br>
runtime.LoadAssembly(assembly);<br> runtime.IO.SetOutput(ms, writer);<br> ScriptEngine engine = runtime.GetEngine(GetEngineName());<br> ScriptScope scope = engine.CreateScope();<br>
<br> string code = string.Format(@"import clr<br>clr.AddReference(""{0}"")<br>import {1}<br>",<br> AssemblyName,<br> AssemblyType.Replace(".py", "")<br>
);<br> ScriptSource source = engine.CreateScriptSourceFromString(<br> code,<br> SourceCodeKind.Statements<br> );<br> source.Execute(scope);<br>
<br>Thanks,<br>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br><a target="_blank" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</blockquote></div><br></div>