<div dir="ltr">clr.AddReference ultimately calls ScriptRuntime.LoadAssembly under the covers -- so the two can be considered equivalent.&nbsp; 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">&lt;<a href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a>&gt;</span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Hi, I&#39;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&#39;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: &quot;No module named System&quot;<br>
&nbsp; at IronPython.Runtime.Builtin.__import__(CodeContext context,<br>String name, Object globals, Object locals, Object fromlist, Int32<br>level)<br>&nbsp; at IronPython.Runtime.Builtin.__import__(CodeContext context,<br>String name, Object globals, Object locals, Object fromlist)<br>
&nbsp; 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>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptRuntimeSetup setup = new ScriptRuntimeSetup();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptRuntime runtime = new ScriptRuntime(setup);<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;runtime.LoadAssembly(assembly);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;runtime.IO.SetOutput(ms, writer);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptEngine engine = runtime.GetEngine(GetEngineName());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptScope scope = engine.CreateScope();<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string code = string.Format(@&quot;import clr<br>clr.AddReference(&quot;&quot;{0}&quot;&quot;)<br>import {1}<br>&quot;,<br>&nbsp; &nbsp; AssemblyName,<br>&nbsp; &nbsp; AssemblyType.Replace(&quot;.py&quot;, &quot;&quot;)<br>
&nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptSource source = engine.CreateScriptSourceFromString(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;code,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SourceCodeKind.Statements<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;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>