[Mono-osx] How to handle returned List<>

liljo lantoine.jo at gmail.com
Sat Apr 7 16:25:50 UTC 2012

I'm embedding Mono in an MacOSX app written in Objective-c.

I'm accessing a C# lib (DDL), which only contains a bunch of static methods
returning different types. So far I can successfully get a returned int,
double and string, but I'm having trouble retrieving a returned array...

For exemple, here's how I retrieve an int:

MonoDomain *domain = mono_jit_init("TestDomain");

NSBundle* mainBundle = [NSBundle mainBundle];
NSString* dll = [mainBundle pathForResource:@"TestLib86" ofType:@"dll"];

MonoAssembly* assembly = mono_domain_assembly_open(domain, [dll

MonoImage* image = mono_assembly_get_image(assembly);


// get a method handle to whatever you like
const char* descAsString = "MiniLib86.Show:GetInt()";
MonoMethodDesc* description = mono_method_desc_new(descAsString,TRUE);
MonoMethod* method = mono_method_desc_search_in_image(description, image);

// call it
void* args[0];
MonoObject *result = mono_runtime_invoke(method, NULL, args, NULL);    
int int_result = *(int*)mono_object_unbox (result);

// See the result in log
NSLog(@"int result %i", int_result);

The method in C# that returns an List looks like this:

public static List<int> GetListInt()
    return new System.Collections.Generic.List<int>{1,2,3,4,5};

Any help would be really appreciated !

View this message in context: http://mono.1490590.n4.nabble.com/How-to-handle-returned-List-tp4539658p4539658.html
Sent from the Mono - OSX mailing list archive at Nabble.com.

More information about the Mono-osx mailing list