1

I have a DLL that exposes this C# event:

[Serializable]
public delegate object[] MyEventHandler(object[] data);

event MyEventHandler MyEvent;

and python code which subscribes to it:

...
def MyPythonEventHandler(source, args):
    print 'Inside Event Handler'
...
ref.MyEvent += MyPythonEventHandler
...

When the DLL fires the event, the print statement in MyPythonEventHandler is not reached; instead Python throws a ConversionException. Because the exception isn't serializable, the DLL actually receives this exception:

System.Runtime.Serialization.SerializationException: Type 'Python.Runtime.
ConversionException' in Assembly 'Python.Runtime, Version=2.0.0.2, Culture=neutral,
PublicKeyToken=null' is not marked as serializable.

So I can't actually tell what conversion is being attempted and is failing.

I successfully handle other event callbacks from this DLL, so I'm guessing this failure has to do with this particular event's delegate signature. Is my python handler's signature wrong?

Thanks, Jim

4

1 回答 1

0

I created a bare bones DLL with one class containing the delegate, event and a Run method that fires the event. Stripped down my python to create the object, subscribe and run. Immediately got an error indicating I hadn't declared a function named MyPythonEventHandler. Found a typo in the name.

Don't get why Python didn't reort this error in the original script, but it works now that I've fixed the name.

于 2013-11-04T14:45:31.827 回答