[Mono-dev] Proper way to construct objects with mono_runtime_invoke
icefragment at gmail.com
Tue Aug 12 22:29:37 EDT 2008
I'm in the initial stages of embedding Mono into my application. I
have a C struct like so (simplified):
const char *name;
I would like to be able to pass a pointer to an object of this type
(allocated globally on the stack) to my managed code constructor,
which will then store it for internal use:
_ent = ent;
The Mono docs state that the way to do this is to get a pointer to the
method and call mono_runtime_invoke (for brevity, I skip asserts on
obj, ctor, and the like, which all pass in my actual code):
obj = mono_object_new(domain, _class); // already asserted _class
!= NULL by this point btw
ctor = findClassMethod(_class, "foo (gentity_t ent)");
// ...setup of testEnt...
args = testEnt;
mono_runtime_invoke(ctor, obj, args, NULL);
All this results in is a System.NullReferenceException upon trying to
access ent in the managed code. Have I missed something obvious in my
setup? I'm using 1.9.1 release (on amd64 Linux).
Thanks in advance for any help.
More information about the Mono-devel-list