[Mono-list] Mono 2.2 - P/Invoke - GetFunctionPointerForDelegate assertion

Ben Henderson bhenderson at ipswitch.com
Thu Mar 19 16:36:21 EDT 2009

Hello all,

I am having an interesting problem with Mono 2.2 with trying to pass a
native function pointer to a function in the same native library.  The
sample code below works with the .NET CLR, but dies in the mono runtime with
the following assertion/error  (I have also tried changing the prototype for
the P/Invoke method to use the delegate, but get the same assertion when
calling the method):

ERROR:marshal.c:9235:mono_marshal_get_managed_wrapper: assertion failed:
method_signature (method)->pinvoke)

This application has requested the Runtime to terminate it in an unusual
Please contact the application's support team for more information.

So.. my question is...  Am I doing something wrong?  Is this not supported
in mono?  Is there a workaround for mono (other than LoadLibrary/dlopen) --
I would like to utilized managed code to do this and not have to add #if's
for different platforms!

Thanks in advance!


******* Code *******

#include "stdafx.h"
#include <stdio.h>

extern "C" void TESTDLL_EXPORT foo()

extern "C" void TESTDLL_EXPORT bar(void (*fn)(void))
	if (fn)

Test Program code:
using System;
using System.Runtime.InteropServices;

namespace FunctionPointerInterop
    class Program
        public extern static void foo();

        public extern static void bar(IntPtr foo);

        public delegate void foo_delegate();

        static foo_delegate my_foo_delegate;

        static void Main(string[] args)
            my_foo_delegate = new foo_delegate(foo);
            IntPtr ptr =

View this message in context: http://www.nabble.com/Mono-2.2---P-Invoke---GetFunctionPointerForDelegate-assertion-tp22608410p22608410.html
Sent from the Mono - General mailing list archive at Nabble.com.

More information about the Mono-list mailing list