[Mono-list] Embedding two assemblies in Mono gives emits NullPointerException

petermonsson petermonsson at yahoo.dk
Mon Sep 13 08:28:21 EDT 2010


Hi Robert,

Thanks for the quick reply.

> I fail to see where you "embed" 2 assemblies. Do you mean
> loading 2 assemblies and executing code from them? 

Yes, that is what I meant.

> Storing a MonoObject* outside the GC-controlled memory area is
> a serious bug. You want to store a GC handle of the object
> in place of the object itself. See mono's mono_gchandle_* APIs. 

So I looked at
http://go-mono.com/docs/index.aspx?link=xhtml%3adeploy%2fmono-api-gchandle.html
and tried to add all the needed mono_gchandle_* method calls, but I'm still
getting a (different) NullPointerException:

Unhandled Exception: System.NullReferenceException: Object reference not set
to an instance of an object
  at MyApp.code.op_Implicit (Sigma300.opcode op) [0x00000] 
  at MyApp.Wrapper.compile (System.String instructions) [0x00000] 

Where did I go wrong this time? Code is below:

Best Regards
Peter


typedef struct ex {
    // ...
    MonoClass *klass_a;
    MonoObject *obj_a;
    guint32 h_obj_a; 
    // ...
    MonoClass *klass_b;
    MonoObject *obj_b;
    guint32 h_obj_b; 

} ex_t;


int ex_new(int a, int b) {
    // ...
    ex->obj_b = mono_object_new(ex->domain, ex->klass_b); // Allocate
storage
    ex->h_obj_b = mono_gchandle_new(ex->obj_b, TRUE);
    mono_runtime_invoke(ex->method_ctor_b,
mono_gchandle_get_target(ex->h_obj_b), NULL, NULL);

    ex->obj_a = mono_object_new(ex->domain, ex->klass_a); // Allocate
storage
    ex->h_obj_a = mono_gchandle_new(ex->obj_a, TRUE);
    gpointer args [2];
    args[0] = &a;
    args[1] = &b;
    mono_runtime_invoke(ex->method_ctor_a,
mono_gchandle_get_target(ex->h_obj_a), args, NULL);

    return 0;
}

int ex_compile(char * string) {
    void *args [1];
    args [0] = mono_string_new(ex->domain, string);

    MonoObject *result = mono_runtime_invoke(ex->method_compile,
mono_gchandle_get_target(ex->h_obj_b), args, NULL);
    return *(int*)mono_object_unbox(result);
}

void ex_delete() {
    // Free objects
    mono_gchandle_free(ex->h_obj_b); 
    mono_gchandle_free(ex->h_obj_a); 

    // Free methods
    mono_method_desc_free(ex->desc_ctor_a);
    mono_method_desc_free(ex->desc_ctor_b);
    mono_method_desc_free(ex->desc_compile);

    // Free mono
    mono_jit_cleanup(ex->domain);

    free(ex);
} 

-- 
View this message in context: http://mono.1490590.n4.nabble.com/Embedding-two-assemblies-in-Mono-gives-emits-NullPointerException-tp2537265p2537333.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list