<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>No. You&#8217;ll have to sync and build<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
users-bounces@lists.ironpython.com [mailto:users-bounces@lists.ironpython.com] <b>On
Behalf Of </b>hellosticky<br>
<b>Sent:</b> Tuesday, August 26, 2008 4:10 PM<br>
<b>To:</b> 'Curt Hagenlocher'; 'Discussion of IronPython'<br>
<b>Subject:</b> Re: [IronPython] Loading DLL from pyc.py into ScriptEngine<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Hi
Curt, yes, i'm using vanilla beta 4. Are there places to grab a nightly drop or
do I need to compile from source?</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Thanks,</span><o:p></o:p></p>

<blockquote style='border:none;border-left:solid black 1.5pt;padding:0in 0in 0in 4.0pt;
margin-left:3.75pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<div class=MsoNormal align=center style='text-align:center'>

<hr size=2 width="100%" align=center>

</div>

<p class=MsoNormal style='margin-bottom:12.0pt'><b><span style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'> Curt Hagenlocher
[mailto:curt@hagenlocher.org] <br>
<b>Sent:</b> Tuesday, August 26, 2008 7:04 PM<br>
<b>To:</b> hellosticky@gmail.com; Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] Loading DLL from pyc.py into ScriptEngine</span><o:p></o:p></p>

<div>

<p class=MsoNormal style='margin-bottom:12.0pt'>Are you using Beta 4?&nbsp; You
probably need to grab a post-beta-4 nightly drop; we got rid of the IsComObject
constructions that don't work in partial trust, but it happened right around
the time Beta 4 was released and may not have made it in.<o:p></o:p></p>

<div>

<p class=MsoNormal>On Tue, Aug 26, 2008 at 3:54 PM, hellosticky &lt;<a
href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a>&gt; wrote:<o:p></o:p></p>

<p class=MsoNormal>Okay, I tried it but got a Security Exception in
System.Scripting.Com.ComMetaObject.IsComObject. The permission requested was
for UnmanagedCode. I'm running in partial trust so obviously I can't be giving
the code UnmanagedCode privilege. Is there some flag I have to set that says
I'm in partial trust?<br>
<br>
FirstPermissionThatFailed:<br>
{&lt;IPermission class=&quot;System.Security.Permissions.SecurityPermission,
mscorlib, Version=<a href="http://2.0.0.0/" target="_blank">2.0.0.0</a>,
Culture=neutral, PublicKeyToken=b77a5c561934e089&quot;<br>
version=&quot;1&quot;<br>
Flags=&quot;UnmanagedCode&quot;/&gt;<br>
}<br>
<br>
Server stack trace:<br>
&nbsp; at
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm,
PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh,
SecurityAction action, Object demand, IPermission permThatFailed)<br>
&nbsp; at
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object
assemblyOrString, PermissionSet granted, PermissionSet refused,
RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission
permThatFailed)<br>
&nbsp; at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet
grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh,
Object assemblyOrString, SecurityAction action, Boolean throwException)<br>
&nbsp; at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack
cs, PermissionSet grants, PermissionSet refused, PermissionSet demands,
RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)<br>
&nbsp; at System.Scripting.Com.ComMetaObject.IsComObject(Object obj)<br>
&nbsp; at System.Scripting.Actions.MetaAction.Bind[T](Object[] args)<br>
&nbsp; at System.Scripting.Actions.CallSite`1.CreateNewRule(Rule`1
originalMonomorphicRule, Object[] args)<br>
&nbsp; at System.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)<br>
&nbsp; at System.Scripting.Actions.UpdateDelegates.Update6[T,T0,T1,T2,T3,T4,T5,TRet](CallSite
site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)<br>
&nbsp; at IronPython.Runtime.Importer.Import(CodeContext context, String
fullName, PythonTuple from, Int32 level)<br>
&nbsp; at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext
context, String fullName, Int32 level)<br>
&nbsp; at &lt;module&gt;$2##2(Closure , Scope , LanguageContext )<br>
&nbsp; at System.Scripting.ScriptCode.InvokeTarget(LambdaExpression code, Scope
scope)<br>
&nbsp; at System.Scripting.Runtime.OptimizedScriptCode.InvokeTarget(LambdaExpression
code, Scope scope)<br>
&nbsp; at System.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)<br>
&nbsp; at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)<br>
&nbsp; at DlrHostedProvider.OnRender()<br>
<br>
Here is the code I used (approximately):<br>
<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StringBuilder sb = new
StringBuilder(100);<br>
<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;using (MemoryStream ms = new
MemoryStream())<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;using (StringWriter
writer = new StringWriter(sb))<o:p></o:p></p>

<div>

<p class=MsoNormal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Assembly
assembly = Assembly.Load(AssemblyName);<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;ScriptRuntime runtime = ScriptRuntime.Create();<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;runtime.LoadAssembly(assembly);<o:p></o:p></p>

</div>

<p class=MsoNormal>&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>
&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>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content = sb.ToString();<br>
<br>
Thanks,<o:p></o:p></p>

<div>

<p class=MsoNormal><br>
&gt; -----Original Message-----<br>
&gt; From: hellosticky [mailto:<a href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a>]<o:p></o:p></p>

</div>

<p class=MsoNormal>&gt; Sent: Tuesday, August 26, 2008 6:46 PM<br>
&gt; To: 'Srivatsn Narayanan'; 'Discussion of IronPython'<br>
&gt; Subject: RE: [IronPython] Loading DLL from pyc.py into ScriptEngine<br>
&gt;<br>
&gt; Thanks, I will try that. Can you explain again how just doing<br>
&gt; &quot;import test&quot; executes the test.py file that was compiled<br>
&gt; into the DLL? It's not very logical..<br>
&gt;<br>
&gt; Thanks,<o:p></o:p></p>

<div>

<p class=MsoNormal>&gt;<br>
&gt; &gt; -----Original Message-----<br>
&gt; &gt; From: Srivatsn Narayanan [mailto:<a
href="mailto:srivatsn@microsoft.com">srivatsn@microsoft.com</a>]<br>
&gt; &gt; Sent: Tuesday, August 26, 2008 6:34 PM<br>
&gt; &gt; To: Discussion of IronPython; <a href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a><br>
&gt; &gt; Subject: RE: [IronPython] Loading DLL from pyc.py into ScriptEngine<br>
&gt; &gt;<br>
&gt; &gt; Also Assembly.Load is not sufficient to be able to import the<br>
&gt; &gt; compiled code. A clr.AddReference needs to be done which<br>
&gt; &gt; publishes the module. The easiest way to do that is include<br>
&gt; &gt; it in the string as Michael pointed out.<br>
&gt; &gt;<o:p></o:p></p>

</div>

<div>

<div>

<p class=MsoNormal>&gt; &gt; ScriptSource source =<br>
&gt; &gt; engine.CreateScriptSourceFromString(&quot;import<br>
&gt; &gt; clr;clr.AddReference(\&quot;test.dll\&quot;);import test&quot;,<br>
&gt; &gt; SourceCodeKind.Statements);<br>
&gt; &gt;<br>
&gt; &gt; You might need to add the current folder to the path as well<br>
&gt; &gt; before the clr.AddReference.<br>
&gt; &gt;<br>
&gt; &gt; -----Original Message-----<br>
&gt; &gt; From: <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a><br>
&gt; &gt; [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>]
On Behalf Of<br>
&gt; Michael Foord<br>
&gt; &gt; Sent: Tuesday, August 26, 2008 3:12 PM<br>
&gt; &gt; To: <a href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a>;
Discussion of IronPython<br>
&gt; &gt; Subject: Re: [IronPython] Loading DLL from pyc.py into ScriptEngine<br>
&gt; &gt;<br>
&gt; &gt; hellosticky wrote:<br>
&gt; &gt; &gt; I also tried:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assembly assembly =
Assembly.Load(AssemblyName);<br>
&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ScriptRuntime runtime
= ScriptRuntime.Create();<br>
&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
runtime.LoadAssembly(assembly);<br>
&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ScriptScope scope =
runtime.ExecuteFile(&quot;test.py&quot;);<br>
&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object o =
scope.Execute(null);<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; But that threw a script not found exception saying it could<br>
&gt; &gt; find the source file for test.py, so it would seem like this<br>
&gt; &gt; wants to recompile it<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;&gt; -----Original Message-----<br>
&gt; &gt; &gt;&gt; From: hellosticky [mailto:<a
href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a>]<br>
&gt; &gt; &gt;&gt; Sent: Tuesday, August 26, 2008 5:52 PM<br>
&gt; &gt; &gt;&gt; To: IronPython<br>
&gt; &gt; &gt;&gt; Subject: Loading DLL from pyc.py into ScriptEngine<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt; Hi,<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt; I created an IronPython DLL with &quot;ipy.exe pyc.py
/out:test<br>
&gt; &gt; &gt;&gt; /target:dll test.py&quot; which created test.dll. Now, from
C#,<br>
&gt; &gt; &gt;&gt; I'd like to execute test.py from test.dll. I just opened up<br>
&gt; &gt; &gt;&gt; dlr-spec-hosting and there's a CreateScriptSourceFromStream,<br>
&gt; &gt; &gt;&gt; but I don't see that in 2.0 Beta 4 bits. Here is where I'm<br>
&gt; &gt; &gt;&gt; stuck. How do I get that assembly into the engine and then<br>
&gt; &gt; &gt;&gt; execute test.py?<br>
&gt; &gt;<br>
&gt; &gt; Well - the easiest way is to execute 'import test' after<br>
&gt; having added<br>
&gt; &gt; the assembly. This should execute the code in order to create<br>
&gt; &gt; a module.<br>
&gt; &gt;<br>
&gt; &gt; ScriptScope scope = engine.CreateScope();<br>
&gt; &gt; ScriptSource source =<br>
&gt; &gt; engine.CreateScriptSourceFromString(&quot;import test&quot;,<br>
&gt; &gt; SourceCodeKind.Statements);<br>
&gt; &gt; engine.Execute(scope);<br>
&gt; &gt;<br>
&gt; &gt; There is an API for setting a stream as stdout on an engine -<br>
&gt; &gt; 'runtime.IO.SetOutput'.<br>
&gt; &gt;<br>
&gt; &gt; Michael<br>
&gt; &gt;<br>
&gt; &gt; &gt;&gt; &nbsp;Also, I'd like to get the output into a<br>
&gt; &gt; &gt;&gt; string (I guess I can just redirect Console.Out?)<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt; public string Execute(string assemblyName)<br>
&gt; &gt; &gt;&gt; {<br>
&gt; &gt; &gt;&gt; &nbsp; &nbsp; string content = null;<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt; &nbsp; &nbsp; Assembly assembly =
Assembly.Load(assemblyName);<br>
&gt; &gt; &gt;&gt; &nbsp; &nbsp; ScriptRuntime runtime =
ScriptRuntime.Create();<br>
&gt; &gt; &gt;&gt; &nbsp; &nbsp; ObjectOperations operations =
runtime.CreateOperations();<br>
&gt; &gt; &gt;&gt; &nbsp; &nbsp; ScriptEngine engine =
runtime.GetEngine(&quot;py&quot;);<br>
&gt; &gt; &gt;&gt; &nbsp; &nbsp; // magic..<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt; &nbsp; &nbsp; return content;<br>
&gt; &gt; &gt;&gt; }<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt; Thanks,<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; _______________________________________________<br>
&gt; &gt; &gt; Users mailing list<br>
&gt; &gt; &gt; <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
&gt; &gt; &gt; <a
href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com"
target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; --<br>
&gt; &gt; <a href="http://www.ironpythoninaction.com/" target="_blank">http://www.ironpythoninaction.com/</a><br>
&gt; &gt; <a href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a><br>
&gt; &gt; <a href="http://www.trypython.org/" target="_blank">http://www.trypython.org/</a><br>
&gt; &gt; <a href="http://www.ironpython.info/" target="_blank">http://www.ironpython.info/</a><br>
&gt; &gt; <a href="http://www.theotherdelia.co.uk/" target="_blank">http://www.theotherdelia.co.uk/</a><br>
&gt; &gt; <a href="http://www.resolverhacks.net/" target="_blank">http://www.resolverhacks.net/</a><br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; Users mailing list<br>
&gt; &gt; <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
&gt; &gt; <a
href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com"
target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
&gt; &gt;<br>
&gt; &gt;<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com"
target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><o:p></o:p></p>

</div>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</blockquote>

</div>

</body>

</html>