[IronPython] IronPython interop problem

Marc-André Belzile mbelzile at softimage.com
Fri Aug 25 22:08:33 CEST 2006

Thanks for the quick answer! I basically want .NET objects to be supported in our product as plug-ins. We currently support C++ plug-ins (with LoadLibray/GetProcAddress) and scripting plugins (which includes jscript, vbscript and python scripting). Plug-ins basically get hooked up through function callbacks.

So if I understand you are suggesting to write a C# object to achieve the interoperabilty with IronPython. Right? Do you have any samples showing how the PythonEngine can be used in this kind of scenario ? That would help me get started.

Thanks for your help!


-----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