I found this bug error while building an application for iPhone using c#.
This application has a plugin that passes System.Object instance to c.I got this and Im not sure what part is missing!
Here is the C# code:
public static void Call( System.IntPtr L, System.Delegate pDelegate)
{
MonoDelegateToPtr( L, 0, pDelegate.Method.Target, pDelegate.Method.Name, pDelegate.Method.GetParameters().Length);
}
[System.Runtime.InteropServices.DllImport("__Internal")]
static extern void MonoDelegateToPtr( System.IntPtr L, int pN, System.Object pObj, string pMethod, int pParamCount);
Here is the C code:
extern "C" void MonoDelegateToPtr( lua_State* L, int pN, MonoObject* pObj, const char* pMethod, int pParamCount)
{
MonoMethod *method;
MonoObject *pObject;
method = GetCSMethod( pObject, pMethod, pParamCount);
lua_CFunction func = (lua_CFunction)[MonoUtility MonoDelToPtr: method];
if( func==0)
{
printf("****ERROR DELEGATE TO FUNCTION PTR IS NULL%s\n", pMethod);
return;
}
lua_pushcclosure( L, func, pN);
}
MonoMethod* GetCSMethod( MonoObject *pObj, const char* pMethod, int pParamsTotal)
{
MonoClass *class = mono_object_get_class( pObj);
MonoMethod *methodDef = mono_class_get_method_from_name( class, pMethod, pParamsTotal);
return mono_object_get_virtual_method((MonoObject*)objectInstance, methodDef);
}
Here is the error msg:
MarshalDirectiveException
at (wrapper managed-to-native) CSharpToMonoClass:MonoDelegateToPtr (intptr,int,object,string,int)
The problem is that the marshaller does not know how to marshal a System.Object.
I believe you can use an IntPtr, and the following trick to transform a System.Object to an IntPtr:
and then store the object in the obj field and read back the pointer from the ptr field.
However I am not entirely sure this is the right approach to what you’re trying to do, but it’s not clear to me what you’re actually trying to do, so maybe you can explain that a bit better?