[IronPython] DLR Hosting, Access to .NET Types

David Seruyange idmkid at yahoo.com
Fri Apr 18 06:28:28 CEST 2008


I think I follow you but I think I can be more specific in getting at what sems to be a subtlety. If you have the following (a file e.g. Spam.py):

import clr
clr.AddReference("System")
from System.Text import *

s = StringBuilder()
print "okay"

It works just fine when executed from a command shell using ipy (ipy Spam.py).  The assumption is that mscorlib is loaded because of the clr.AddReference("System"). 
But when using a hosted engine, mscorlib seems not to be loaded for free anymore - 

ScriptEngine engine = PythonEngine.CurrentEngine;
engine.Runtime.ExecuteFile("Spam.py")

Now the reference that came for "free" before to mscorlib seems not to be present.

----- Original Message ----
From: Curt Hagenlocher <curt at hagenlocher.org>
To: Discussion of IronPython <users at lists.ironpython.com>
Sent: Thursday, April 17, 2008 10:39:49 PM
Subject: Re: [IronPython] DLR Hosting, Access to .NET Types

On Thu, Apr 17, 2008 at 8:33 PM, David Seruyange <idmkid at yahoo.com> wrote:
>
> Are all framework types accessible from a hosted engine?  While the module
> loads fine using the above code, a reference to the StringBuilder (which
> works fine when executing a file that references the module) produces an
> error "name StringBuilder not defined." (The module does have a "from
> System.Text import *") -

The console does the equivalent of the following:

    runtime.LoadAssembly(typeof(string).Assembly);
    runtime.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly);

You'll need to execute similar code if you want to access the same assemblies

--
Curt Hagenlocher
curt at hagenlocher.org
_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com






      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080417/088399cc/attachment.html>


More information about the Ironpython-users mailing list