0

I have been following the guidance given on this other post:

Assigning an IronPython method to a C# delegate

This post also references another resource on the darker corners of IronPython that has some useful information:

http://www.voidspace.org.uk/ironpython/dark-corners.shtml

I am trying to invoke an IronPython method from C# as a delegate. My latest attempt looks as follows (using System.Action):

IronPython Code:

delegate = Action[String](self.testErrorDelegate);
#csharp library method call
csharp_library.InvokeAction(delegate);

...

@unittest.skip("dev skipping")
def testErrorDelegate(self,message):
    print "error delegate"
    print message;

csharp library code:

public void InvokeAction(Action<string> listener)
{
    Console.WriteLine("BEFORE INVOKE");
    listener("DO SOMETHING");
    Console.WriteLine("AFTER INVOKE");
}

My problem is I get no output from the python testErrorDelegate when running this. No runtime errors either. I see the C# Console.WriteLine statements but "DO SOMETHING" is never printed.

Any idea on what I could be doing wrong here?

I have also tried doing the same approach casting directly to a C# delegate from the python method. I saw the same behavior using that approach, i.e. verification of C# method call, but not return call to python code via delegate.

I am using IronPython 2.7.1 (ipy.exe).

Community
  • 1
  • 1
Ryan R.
  • 2,478
  • 5
  • 27
  • 48

1 Answers1

1

It looks like this was an issue with using a reference to a function that was a skipped "unittest".

I had:

@unittest.skip("dev skipping")
def testErrorDelegate(self,message):
    print "error delegate"
    print message;

changed to:

def errorDelegate(self,message):
    print "error delegate"
    print message;

I also changed to using inheritance from a CLR class in the Python code to keep the function registration done entirely in the python code.

I guess the @unittest.skip annotation does something strange with the visibility of the method?

Ryan R.
  • 2,478
  • 5
  • 27
  • 48