[Mono-dev] Create a 'MonoImage' from a byte array. (corrected)

Thiago Padilha tpadilha84 at gmail.com
Wed Jun 16 11:49:37 EDT 2010


 I'm trying to create a MonoImage/MonoAssembly from a byte array like this :


//body omited, this is a simple function that return contents of a
binary file and returns the file size in bytes as an out parameter
static char *read_file_contents(char *fullpath, int *outfilesize);

static char *getfullpath(char *name); //returns the full path of a file

static MonoImage *get_image(char *data, char *name, char *size)
{
       return  mono_image_open_from_data_with_name (data, size, 0,
MONO_IMAGE_OK, 0, name);
}

MonoAssembly *get_assembly_from_file(char *name)
{
       int size = 0;
       char *fullpath =  getfullpath(name);
       char *data = read_file_contents(fullpath, &size);


       MonoAssembly *ret = NULL;
       MonoImage *image = get_image(data, name, size);

       if(image != NULL)
               ret = mono_assembly_load_from_full(image, fullpath,
MONO_IMAGE_OK, 0);

       return ret;
}

I get some assertion errors in glib when creating the image trough
'mono_image_open_from_data_with_name' :

(process:24477): GLib-CRITICAL **: g_hash_table_lookup: assertion
`hash_table != NULL' failed

(process:24477): GLib-CRITICAL **: g_hash_table_insert_internal:
assertion `hash_table != NULL' failed

(process:24477): GLib-CRITICAL **: g_hash_table_lookup: assertion
`hash_table != NULL' failed

(process:24477): GLib-CRITICAL **: g_hash_table_insert_internal:
assertion `hash_table != NULL' failed
f

  Am I missing something? if so, how can I create a 'MonoAssembly'
from a byte array?(instead of using the  'mono_assembly_open' which
accepts a filename).


More information about the Mono-devel-list mailing list