[IronPython] BeginInvoke from C# to IronPython

Matthew Green babygguy at gmail.com
Sun Apr 10 06:47:00 CEST 2011

Hi everyone,

I came across a simple C# httplistener
I decided to have a quick play with it and leave the listener in C#
and make the client calls and callback in IronPython. After multiple
attempts I failed to get C#'s BeginInvoke call to callback to
IronPython. That catch shows a "The object must be a runtime
Reflection object." error.

I implemented this short example which failed to callback to the
Python function and hits the catch after trying to BeginInvoke -
using System;
using System.Globalization;
using System.Net;
using System.Threading;

namespace test
    public class Class1
        public event EventHandler<SomeEventArgs> IncomingRequest = null;

        public void testInvoke()
            SomeEventArgs e = new SomeEventArgs(1);
                if (this.IncomingRequest != null)
                    this.IncomingRequest.BeginInvoke(this, e, null, null);

public class SomeEventArgs : EventArgs
    public int RequestContext;

    public SomeEventArgs(int anarg)
        this.RequestContext = anarg;

import clr
from test import *

def testcallback(foo, bar):

thing = Class1()
thing.IncomingRequest += testcallback

I get the feeling I'm missing some basic knowledge about how
IronPython functions are added as events. But I feel like I'm getting
distracted and looking at all the wrong things. Thanks for your

More information about the Ironpython-users mailing list