[IronPython] Embedded IronPython engine, access to heap objects

Dino Viehland dinov at microsoft.com
Fri Jul 16 20:49:17 CEST 2010


There's no need to wrap - you can just put an instance in the ScriptScope which you're executing against and it'll be available.  Just make sure the class is public (or it implements a public interface) and the members you want accessible are also public.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Bakalar, Matthew (NIH/CIT) [C]
Sent: Friday, July 16, 2010 7:20 AM
To: Discussion of IronPython
Subject: [IronPython] Embedded IronPython engine, access to heap objects

Hello All,
I am trying to embed an IronPython engine and console into a C# application to provide the user with a simple way to execute scripts. I would like the scripts to have access to objects created within the C# application. I have reviewed many examples on creating IronPython console applications and executing statements and scripts from within compiled C# apps, but haven't found any references to help me gain access to C# objects from the engine I create. Is there a way to wrap C# objects for use in the IronPython engine?
Thanks,
Matt Bakalar

From: Bakalar, Matthew (NIH/CIT) [C]
Sent: Tuesday, June 01, 2010 3:35 PM
To: 'Discussion of IronPython'
Subject: RE: Uninformative Type Error

Thank you very much Dino, I added the folders that contain my assemblies to sys.path and then used clr.AddReference to add a reference to them. The type error no longer exists.
Matt Bakalar


From: Dino Viehland [mailto:dinov at microsoft.com]
Sent: Tuesday, June 01, 2010 1:41 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Uninformative Type Error

This is caused by having the same assembly loaded into 2 different loader contexts at once (loader contexts are a part of the CLR loading infrastructure).  Adding references to assemblies by file can be tricky.  One possible solution might be to install both assemblies into the GAC and then do clr.AddReference.  Another might be to make sure they're next to ipy.exe (or whatever the host process is if it's not ipy.exe) and then also do a clr.AddReference.  You could also attempt to debug where the assemblies are getting loaded and try to make the add reference to file work - that would involve using fuslogvw.exe (logging all loads) and probably looking at PythonContext.TryLoadAssemblyFromFileWithPath.  But the other choices are probably much easier and more robust.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Bakalar, Matthew (NIH/CIT) [C]
Sent: Tuesday, June 01, 2010 7:15 AM
To: Discussion of IronPython
Subject: [IronPython] Uninformative Type Error

Hello All,
I am running into a frustrating exception. When attempting to instantiate a class with an argument that is an instance of a different class from a separate assembly, I receive an unhelpful type error from the IronPython interpreter:
TypeError: expected XYZPositioner, got XYZPositioner
Both assemblies were loaded using clr.AddReferenceToFileAndPath. I have tried to confirm the type of the object I am passing as an argument to the constructor:
> A.GetType() == Target.Devices.XYZPositioner
True
Is there any way to get more information about the error? (The message reminds me of my days working in OCaml, where all of the error messages were translated from French grammar and it was never clear how to differentiate the object from the subject)
Thanks,
Matt Bakalar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100716/a6ac7eb3/attachment.html>


More information about the Ironpython-users mailing list