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).

1
  • FYI, the language is named "C#", not "csharp". Commented Feb 16, 2012 at 2:51

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.