[IronPython] IronPython interop problem

Marc-André Belzile mbelzile at softimage.com
Mon Aug 28 22:25:06 CEST 2006


Do you have plans in the future to make IP assemblies COM visible? This would allow us to support .NET assemblies in a uniform manner without having to do a special case for IP.

As for the approach you are proposing, it's not obvious how I can use PythonEngine for my scenario. Our plug-ins need to expose a set of functions known by the main app. These functions are called by the app with SDK objects arguments (i.e ActiveX), these objects are used by the callback to perform some actions. I don't see any methods in PythonEngine that would allow me to do such things.


PtyhonEngine engine = new PtyhonEngine

ArrayList args;
args.Add( obj1 );
args.Add( obj2 );

Boolean retVal;
engine.Execute( "Foo", args, retVal );


Foo would be defined as

def Foo( arg0, arg1 ):
	return true

Are these kind of things possible to do with the current implementation of IP ?



-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com]On Behalf Of Dino Viehland
Sent: August 25, 2006 3:47 PM
To: Discussion of IronPython
Subject: Re: [IronPython] IronPython interop problem

The problem you're running into is that we won't expose the Python type by the names you compile it as - this is the weirdness you're seeing versus a C# compiled assembly.

There's a couple of ways to deal with this.  One is to host IronPython and use the PythonEngine interfaces to expose objects, create instances, etc...  This is the preferred mechanism - for your scenario you may need to make a small shim in C# that enables access to the IronPython engine because we don't mark the type as being ComVisible (and we explicitly turn off COM visibility for all types in the assembly unless they opt-in).  I'm actually not certain if our types that get created on the fly are COM visible, but even if they are IDispatch currently won't know about the way we plug-in here.

We also have a HIGHLY EXPERIMENTAL static type compiler - unfortunately there is plenty of valid Python code that can't be compiled by it yet so I'd suggest you go with the 1st route.

This is a very interesting scenario though and we'll probably want to look at what we can do in the future to make this better.  If you want to let us know more about what you're trying to accomplish in the end it might help us ensure this meets your needs in the future.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Marc-André Belzile
Sent: Friday, August 25, 2006 11:11 AM
To: users at lists.ironpython.com
Subject: [IronPython] IronPython interop problem


I'm hosting the CLR (.NET 2.0) in an unmanaged C++ app in order to access objects from .NET assemblies with IDispatch. This is working fine for C# assemblies but failed for IP assemblies.

The call to _AppDomain.CreateInstance below returns this error: 80131522, which I couldn't find in the doc.

My unmanaged code:

        CComPtr<_AppDomain> spAppDomain;
        HRESULT hr = pDomain->QueryInterface( &spAppDomain.p );
        assert( !hr );

        CComPtr<_ObjectHandle> spHandle;
        CComBSTR assyname("IronPythonPlugin");
        CComBSTR classname("MyClass");

        hr = spAppDomain->CreateInstance( assyname,classname,&spHandle );

My test class in

        class MyClass:
                def Foo():

I compiled the PI assbly with VS2005 using the IDE prototype. The IL code looks rather odd though compared to a C# assbly.

___[MOD] S:\Rayflex\Sdk\si3dobjectmodel\IronPythonPlugin\bin\Debug\IronPythonPlugin.dll
   |      M A N I F E S T
   |___[CLS] Class
   |   |     .class public auto ansi
   |   |      extends [IronPython]IronPython.Runtime.CustomDict
   |   |___[STF] ExtraKeysCache : public static string[]
   |   |___[STF] MyClass : public static object
   |   |___[STF] __doc__ : public static object
   |   |___[STF] __name__ : public static object
   |   |___[STF] myModule__py : public static class [IronPython]IronPython.Runtime.PythonModule
   |   |___[STM] .cctor : void()
   |   |___[MET] .ctor : void()
   |   |___[STM] Foo$f4 : object(class [IronPython]IronPython.Runtime.FunctionEnvironment4)
   |   |___[MET] GetExtraKeys : object[]()
   |   |___[MET] Initialize : void()
   |   |___[STM] Main : int32()
   |   |     MyClass$maker4 : class [mscorlib]System.Collections.Generic.IDictionary`2<object,object>(class [IronPython]IronPython.Runtime.FunctionEnvironment,class [IronPython]IronPython.Runtime.ICallerContext)
   |   |___[MET] TryGetExtraValue : bool(object,object&)
   |   |___[MET] TrySetExtraValue : bool(object,object)

Is this a known limitation ? Or maybe there is another way of getting at IP classes from unmanaged code ?

thanks for your help!

Marc-André BELZILE - sdk software engineer, softimage|xsi _______________________________________________
users mailing list
users at lists.ironpython.com
users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list