[Mono-list] Embedding two assemblies in Mono gives emits NullPointerException
petermonsson
petermonsson at yahoo.dk
Mon Sep 13 07:28:57 EDT 2010
Hi all,
I'm trying to embed two different assemblies into my mono application.
Embedding just either of them is no problem, but when I try to embed both, I
get a NullPointerException.
Unhandled Exception: System.NullReferenceException: Object reference not set
to an instance of an object
at Mono.Globalization.Unicode.SimpleCollator.MatchesBackward
(System.String s, System.Int32& idx, Int32 end, Int32 orgStart, Int32 ti,
System.Byte* sortkey, Boolean noLv4, Mono.Globalization.Unicode.Context&
ctx) [0x00000]
at Mono.Globalization.Unicode.SimpleCollator.LastIndexOfSortKey
(System.String s, Int32 start, Int32 orgStart, Int32 length, System.Byte*
sortkey, Int32 ti, Boolean noLv4, Mono.Globalization.Unicode.Context& ctx)
[0x00000]
at Mono.Globalization.Unicode.SimpleCollator.LastIndexOf (System.String s,
System.String target, Int32 start, Int32 length, System.Byte* targetSortKey,
Mono.Globalization.Unicode.Context& ctx) [0x00000]
at Mono.Globalization.Unicode.SimpleCollator.LastIndexOf (System.String s,
System.String target, Int32 start, Int32 length, CompareOptions opt)
[0x00000]
at Mono.Globalization.Unicode.SimpleCollator.IsSuffix (System.String s,
System.String target, Int32 start, Int32 length, CompareOptions opt)
[0x00000]
at Mono.Globalization.Unicode.SimpleCollator.IsSuffix (System.String src,
System.String target, CompareOptions opt) [0x00000]
at System.Globalization.CompareInfo.IsSuffix (System.String source,
System.String suffix, CompareOptions options) [0x00000]
at System.String.EndsWith (System.String value) [0x00000]
at MyApp.FileIO.set_directory (System.String value) [0x00000]
at MyApp.Builder.Build () [0x00000]
at MyApp.BuilderWrapper.compile (System.String instructions) [0x00000]
Here is my code:
// For MonoDomain, MonoAssembly
#include <mono/jit/jit.h>
//For MonoImage
#include <mono/metadata/assembly.h>
//For MonoMethodDesc
#include <mono/metadata/debug-helpers.h>
//#include <string.h>
#include <malloc.h>
#include <stdio.h>
#define SETUP_DEF(id) \
MonoMethodDesc *desc_##id; \
MonoMethod *method_##id; \
typedef struct ex {
// Getting started
MonoDomain *domain;
MonoAssembly *assembly_a;
MonoImage *image_a;
// Getting access to a class
MonoClass *klass_a;
MonoObject *obj_a;
// Getting access to the methods
SETUP_DEF(ctor_a);
MonoAssembly *assembly_b;
MonoImage *image_b;
// Getting access to a class
MonoClass *klass_b;
MonoObject *obj_b;
// Getting access to the methods
SETUP_DEF(ctor_b);
SETUP_DEF(compile);
} ex_t;
ex_t * ex;
#define SETUP_METHOD(id,name,err0,err1,klassname) \
ex->desc_##id = mono_method_desc_new(name, FALSE); \
if (!ex->desc_##id) return err0; \
ex->method_##id = mono_method_desc_search_in_class(ex->desc_##id,
ex->klass_##klassname); \
if (!ex->method_##id) return err1; \
int ex_new(int a, int b) {
// Getting started
ex = NULL;
ex = (ex_t *) malloc(sizeof(ex_t));
if (!ex) return 127;
ex->domain = mono_jit_init(EXE_FILE_NAME_B);
//ex->domain = mono_jit_init(EXE_FILE_NAME_A);
ex->assembly_b = mono_domain_assembly_open (ex->domain,
EXE_FILE_NAME_B);
if (!ex->assembly_b) return 2; //Quick hard fail
ex->assembly_a = mono_domain_assembly_open (ex->domain,
EXE_FILE_NAME_A);
if (!ex->assembly_a) return 2; //Quick hard fail
ex->image_b = mono_assembly_get_image(ex->assembly_b);
if (!ex->image_b) return 3;
ex->image_a = mono_assembly_get_image(ex->assembly_a);
if (!ex->image_a) return 3;
// Getting access to a class
ex->klass_b = mono_class_from_name (ex->image_b, EX_NAMESPACE_B,
EX_CLASS_NAME_B); //Get Class
if (!ex->klass_b) return 4;
ex->klass_a = mono_class_from_name (ex->image_a, EX_NAMESPACE_A,
EX_CLASS_NAME_A); //Get Class
if (!ex->klass_a) return 4;
// Getting access to methods in a class
SETUP_METHOD(ctor_b, ":.ctor()", 10, 11, b);
SETUP_METHOD(compile, ":compile", 12, 13, b);
SETUP_METHOD(ctor_a, ":.ctor(int,int)", 14, 15, a);
// Init a singleton object
ex->obj_b = mono_object_new(ex->domain, ex->klass_b); // Allocate
storage
mono_runtime_invoke(ex->method_ctor_b, ex->obj_b, NULL, NULL);
ex->obj_a = mono_object_new(ex->domain, ex->klass_a); // Allocate
storage
gpointer args [2];
args[0] = &a;
args[1] = &b;
mono_runtime_invoke(ex->method_ctor_a, ex->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, ex->obj_b,
args, NULL);
return *(int*)mono_object_unbox(result);
}
void asm_delete() {
// 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);
}
int main(int argc, char* argv[]) {
printf("Starting out\n");
int res = ex_new(2*4096, 4*5120);
if (res != 0)
printf("Init failed %d\n", res);
printf("Initialized\n");
ex_compile("A0 = B0");
printf("Deleting\n");
ex_delete();
printf("Done\n");
return 0;
}
--
View this message in context: http://mono.1490590.n4.nabble.com/Embedding-two-assemblies-in-Mono-gives-emits-NullPointerException-tp2537265p2537265.html
Sent from the Mono - General mailing list archive at Nabble.com.
More information about the Mono-list
mailing list