[IronPython] Marking Methods as Scriptable from IronPython with Silverlight (and problems therein)
jomes at microsoft.com
Fri Jul 20 04:19:58 CEST 2007
What happens if you change method() to return a string, e.g.:
public string method()
Does that help?
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
Sent: Thursday, July 19, 2007 4:33 PM
To: Discussion of IronPython
Subject: [IronPython] Marking Methods as Scriptable from IronPython with Silverlight (and problems therein)
Hello all (especially John),
The way to call into managed code is to mark classes and methods with a
Scriptable attribute. Obviously you can't do this from IronPython -
still no attributes support ;-). The obvious way to attempt is to create
a C# class with the attributes and subclass from IronPython.
I have a basic C# example working, so I know I'm on the right track.
Unfortunately it fails to work from IronPython (either using the C#
class directly or a subclass). The error is:
Script object of type 'ScriptableClass.Class' contains a script member
'method' with an invalid type ('System.Object').
Exception Details: System.NotSupportedException: Script object of type
'ScriptableClass.Class' contains a script member 'method' with an
invalid type ('System.Object')..
at OnLoad in test.py, line 22
This could be because it is only valid to return a string or other
primitive type from a Scriptable method. I wonder if when done from
inside IronPython the method signature is mutated to appear as if it
returns Object ?
Here is the basic C# code:
public class Class
public object method()
public object _method()
The Python code that calls it (adding the reference is working now - God
knows why - must have been an oddity on my system - sorry):
clr.AddReference("ScriptableObjects, Version=220.127.116.11, Culture=neutral,
from System.Windows import WebApplication
from System.Windows.Browser import HtmlPage
from ScriptableClass import Class
def OnLoad(sender, e):
example1 = Class()
example2 = Subclass()
The error is at the *first* call to "RegisterScriptableObject" - so it
isn't even with the subclass...
If anyone has any clues as to how I might work round this then it would
be much appreciated. (I have already tried moving the call to
"RegisterScriptableObject" into C#, but still passing in instances
created in Python code and this made no difference.)
All the best,
users mailing list
users at lists.ironpython.com
More information about the Ironpython-users