[Ironpython-users] MethodInfo Runtime Object

Markus Schaber m.schaber at 3s-software.com
Mon Nov 28 16:02:43 CET 2011


Hi,

We have some existing C# classes using a custom event implementation which calls delegates via reflection[1]. Now, when subscribing to the event exposed by that class via IronPython, an ArgumentException is thrown:

Unbehandelte Ausnahme: System.ArgumentException: MethodInfo muss ein MethodInfo-Laufzeitobjekt sein.
Parametername: this
   bei System.Reflection.Emit.DynamicMethod.RTDynamicMethod.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture)
   bei System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   bei EventTest.Invoke(Object[] args) in D:\playgroundSharpDevelop\IronPythonDelegateTest\Program.cs:Zeile 98.
   bei ScriptExecutor.Main() in D:\playgroundSharpDevelop\IronPythonDelegateTest\Program.cs:Zeile 37.
Script Finished

I attached a stripped down example program demonstrating this behavior.

Currently, we have a workaround of using a C# wrapper method as demonstrated in the example code, but this is cumbersome, as we need to create a C# wrapper for every exposed delegate type which uses that custom event implementation internally, and we need to call that wrapper explicitly from the script.

I also want to avoid to rewrite the custom event implementation, as one of our goals is to add the scripting capability in a non-intrusive way.

Now is there any way I can create a working MethodInfo object from pure IronPython?

Best regards

Markus Schaber

[1] The main reason for this custom event implementation is that this implementation internally keeps the references to the delegate target as weak references, so that subscribing to that event alone does not prevent the object from being collected.

-- 
___________________________
We software Automation.

3S-Smart Software Solutions GmbH
Markus Schaber | Developer
Memminger Str. 151 | 87439 Kempten | Germany | Tel. +49-831-54031-0 | Fax +49-831-54031-50

Email: m.schaber at 3s-software.com | Web: http://www.3s-software.com 
CoDeSys internet forum: http://forum.3s-software.com
Download CoDeSys sample projects: http://www.3s-software.com/index.shtml?sample_projects

Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915 



More information about the Ironpython-users mailing list