<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’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> </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> </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> </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? 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 <<a
href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a>> 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>
{<IPermission class="System.Security.Permissions.SecurityPermission,
mscorlib, Version=<a href="http://2.0.0.0/" target="_blank">2.0.0.0</a>,
Culture=neutral, PublicKeyToken=b77a5c561934e089"<br>
version="1"<br>
Flags="UnmanagedCode"/><br>
}<br>
<br>
Server stack trace:<br>
at
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm,
PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh,
SecurityAction action, Object demand, IPermission permThatFailed)<br>
at
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object
assemblyOrString, PermissionSet granted, PermissionSet refused,
RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission
permThatFailed)<br>
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet
grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh,
Object assemblyOrString, SecurityAction action, Boolean throwException)<br>
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack
cs, PermissionSet grants, PermissionSet refused, PermissionSet demands,
RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)<br>
at System.Scripting.Com.ComMetaObject.IsComObject(Object obj)<br>
at System.Scripting.Actions.MetaAction.Bind[T](Object[] args)<br>
at System.Scripting.Actions.CallSite`1.CreateNewRule(Rule`1
originalMonomorphicRule, Object[] args)<br>
at System.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)<br>
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>
at IronPython.Runtime.Importer.Import(CodeContext context, String
fullName, PythonTuple from, Int32 level)<br>
at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext
context, String fullName, Int32 level)<br>
at <module>$2##2(Closure , Scope , LanguageContext )<br>
at System.Scripting.ScriptCode.InvokeTarget(LambdaExpression code, Scope
scope)<br>
at System.Scripting.Runtime.OptimizedScriptCode.InvokeTarget(LambdaExpression
code, Scope scope)<br>
at System.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)<br>
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)<br>
at DlrHostedProvider.OnRender()<br>
<br>
Here is the code I used (approximately):<br>
<br>
StringBuilder sb = new
StringBuilder(100);<br>
<br>
using (MemoryStream ms = new
MemoryStream())<br>
{<br>
using (StringWriter
writer = new StringWriter(sb))<o:p></o:p></p>
<div>
<p class=MsoNormal> {<br>
Assembly
assembly = Assembly.Load(AssemblyName);<br>
ScriptRuntime runtime = ScriptRuntime.Create();<br>
runtime.LoadAssembly(assembly);<o:p></o:p></p>
</div>
<p class=MsoNormal>
runtime.IO.SetOutput(ms, writer);<br>
ScriptEngine engine = runtime.GetEngine(GetEngineName());<br>
ScriptScope scope = engine.CreateScope();<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>
}<br>
content = sb.ToString();<br>
<br>
Thanks,<o:p></o:p></p>
<div>
<p class=MsoNormal><br>
> -----Original Message-----<br>
> From: hellosticky [mailto:<a href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a>]<o:p></o:p></p>
</div>
<p class=MsoNormal>> Sent: Tuesday, August 26, 2008 6:46 PM<br>
> To: 'Srivatsn Narayanan'; 'Discussion of IronPython'<br>
> Subject: RE: [IronPython] Loading DLL from pyc.py into ScriptEngine<br>
><br>
> Thanks, I will try that. Can you explain again how just doing<br>
> "import test" executes the test.py file that was compiled<br>
> into the DLL? It's not very logical..<br>
><br>
> Thanks,<o:p></o:p></p>
<div>
<p class=MsoNormal>><br>
> > -----Original Message-----<br>
> > From: Srivatsn Narayanan [mailto:<a
href="mailto:srivatsn@microsoft.com">srivatsn@microsoft.com</a>]<br>
> > Sent: Tuesday, August 26, 2008 6:34 PM<br>
> > To: Discussion of IronPython; <a href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a><br>
> > Subject: RE: [IronPython] Loading DLL from pyc.py into ScriptEngine<br>
> ><br>
> > Also Assembly.Load is not sufficient to be able to import the<br>
> > compiled code. A clr.AddReference needs to be done which<br>
> > publishes the module. The easiest way to do that is include<br>
> > it in the string as Michael pointed out.<br>
> ><o:p></o:p></p>
</div>
<div>
<div>
<p class=MsoNormal>> > ScriptSource source =<br>
> > engine.CreateScriptSourceFromString("import<br>
> > clr;clr.AddReference(\"test.dll\");import test",<br>
> > SourceCodeKind.Statements);<br>
> ><br>
> > You might need to add the current folder to the path as well<br>
> > before the clr.AddReference.<br>
> ><br>
> > -----Original Message-----<br>
> > From: <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a><br>
> > [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>]
On Behalf Of<br>
> Michael Foord<br>
> > Sent: Tuesday, August 26, 2008 3:12 PM<br>
> > To: <a href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a>;
Discussion of IronPython<br>
> > Subject: Re: [IronPython] Loading DLL from pyc.py into ScriptEngine<br>
> ><br>
> > hellosticky wrote:<br>
> > > I also tried:<br>
> > ><br>
> > > Assembly assembly =
Assembly.Load(AssemblyName);<br>
> > > ScriptRuntime runtime
= ScriptRuntime.Create();<br>
> > >
runtime.LoadAssembly(assembly);<br>
> > > ScriptScope scope =
runtime.ExecuteFile("test.py");<br>
> > > object o =
scope.Execute(null);<br>
> > ><br>
> > > But that threw a script not found exception saying it could<br>
> > find the source file for test.py, so it would seem like this<br>
> > wants to recompile it<br>
> > ><br>
> > ><br>
> > >> -----Original Message-----<br>
> > >> From: hellosticky [mailto:<a
href="mailto:hellosticky@gmail.com">hellosticky@gmail.com</a>]<br>
> > >> Sent: Tuesday, August 26, 2008 5:52 PM<br>
> > >> To: IronPython<br>
> > >> Subject: Loading DLL from pyc.py into ScriptEngine<br>
> > >><br>
> > >> Hi,<br>
> > >><br>
> > >> I created an IronPython DLL with "ipy.exe pyc.py
/out:test<br>
> > >> /target:dll test.py" which created test.dll. Now, from
C#,<br>
> > >> I'd like to execute test.py from test.dll. I just opened up<br>
> > >> dlr-spec-hosting and there's a CreateScriptSourceFromStream,<br>
> > >> but I don't see that in 2.0 Beta 4 bits. Here is where I'm<br>
> > >> stuck. How do I get that assembly into the engine and then<br>
> > >> execute test.py?<br>
> ><br>
> > Well - the easiest way is to execute 'import test' after<br>
> having added<br>
> > the assembly. This should execute the code in order to create<br>
> > a module.<br>
> ><br>
> > ScriptScope scope = engine.CreateScope();<br>
> > ScriptSource source =<br>
> > engine.CreateScriptSourceFromString("import test",<br>
> > SourceCodeKind.Statements);<br>
> > engine.Execute(scope);<br>
> ><br>
> > There is an API for setting a stream as stdout on an engine -<br>
> > 'runtime.IO.SetOutput'.<br>
> ><br>
> > Michael<br>
> ><br>
> > >> Also, I'd like to get the output into a<br>
> > >> string (I guess I can just redirect Console.Out?)<br>
> > >><br>
> > >> public string Execute(string assemblyName)<br>
> > >> {<br>
> > >> string content = null;<br>
> > >><br>
> > >> Assembly assembly =
Assembly.Load(assemblyName);<br>
> > >> ScriptRuntime runtime =
ScriptRuntime.Create();<br>
> > >> ObjectOperations operations =
runtime.CreateOperations();<br>
> > >> ScriptEngine engine =
runtime.GetEngine("py");<br>
> > >> // magic..<br>
> > >><br>
> > >> return content;<br>
> > >> }<br>
> > >><br>
> > >> Thanks,<br>
> > >><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><br>
> > ><br>
> ><br>
> ><br>
> > --<br>
> > <a href="http://www.ironpythoninaction.com/" target="_blank">http://www.ironpythoninaction.com/</a><br>
> > <a href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a><br>
> > <a href="http://www.trypython.org/" target="_blank">http://www.trypython.org/</a><br>
> > <a href="http://www.ironpython.info/" target="_blank">http://www.ironpython.info/</a><br>
> > <a href="http://www.theotherdelia.co.uk/" target="_blank">http://www.theotherdelia.co.uk/</a><br>
> > <a href="http://www.resolverhacks.net/" target="_blank">http://www.resolverhacks.net/</a><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><br>
> ><br>
> ><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> </o:p></p>
</div>
</blockquote>
</div>
</body>
</html>