[IronPython] (UPDATE) Cannot create instances of RuntimeType because it has no public constructors

Marcel Heing-Becker marscel at googlemail.com
Mon Dec 28 18:45:03 CET 2009


Thanks, this seems to work. This exposes my whole namepsace to IronPython
but I think, it seems to be sufficiant to mark classes and types that must
stay off this scope with 'internal'.

2009/12/28 Curt Hagenlocher <curt at hagenlocher.org>

> "fooclass" is not a Python type. It's an instance of the CLR class
> System.RuntimeType. In order to derive from "foo" in this fashion, you might
> be able to turn fooclass into a IronPython.Runtime.Types.PythonType by
> saying
>
> import clr
> foo = clr.GetPythonType(fooclass)
> class bar(foo):
>     pass
>
> If it's consistent with your security requirements, it would be simpler to
> simply expose your C# assembly directly to IronPython. You would do this
> from within the C# code by saying
>
> scriptRuntime.LoadAssembly(typeof(foo).Assembly);
>
> and then you could say from your Python code
>
> from Namespace.Containing.Your.Foo.Class import foo
>
> On Mon, Dec 28, 2009 at 4:36 AM, Marcel Heing-Becker <
> marscel at googlemail.com> wrote:
>
>> PLEASE IGNORE MY PREVIOUS POST with the same title, I accidentally sent it
>> before I was finished cleaning up the code.
>>
>> Hi there,
>> I have a problem with my application. It's written in C# and embeds
>> IronPython. In C#, I have a class that looks like this:
>>
>> public class foo
>> {
>>     public foo()
>>     {
>>         ...
>>     }
>>     ...
>> }
>>
>> I put this into the ScriptScope I use by doing:
>>
>> scope.SetVariable("fooclass", typeof(foo));
>>
>> Operations like: a = fooclass() work without any problem, but the
>> following IronPython does not work and raises the error: Cannot create
>> instances of RuntimeType because it has no public constructors. Code:
>>
>> class bar(fooclass):
>>     def __init__(self):
>>         Name = "Unused"
>>     ...
>>
>> barobject = bar()
>>
>> Well, I can't really say what this is about. Is it a Bug in IP or anything
>> like a limitation?
>> Greetings, Marcel
>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>>
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20091228/b6a4d38c/attachment.html>


More information about the Ironpython-users mailing list