i didn't list any specific crash, because i tried in a million different ways and got a different crash each time.
i've solved this now. it seems, a unmanaged thunk takes a hidden additional parameter, MonoException ** which can't be NULL. of course this isn't documented anywhere. for reference, i got the mentioned call working using: typedef MonoObject* (*ParseToJSON) (MonoString *obj1,MonoException **obj2); ParseToJSON func = mono_method_get_unmanaged_thunk(method); MonoString *s1 = mono_string_new (domain, "A-B"); MonoException *exc = NULL; MonoObject *result = func(s1,&exc); MonoString *resultstring = mono_object_to_string(result, NULL); char *resultCString = mono_string_to_utf8(resultstring); > On 11.11.2015, at 21:34, Rodrigo Kumpera <kump...@gmail.com> wrote: > > How does it crash? Did you try debugging it? > > The invocation looks ok. > > On Wed, Nov 11, 2015 at 3:03 PM, Core_Code <jul...@corecode.at> wrote: > hello, > > we are currently embedding Mono to use a C# DLL, which works fine. > > we are using mono_runtime_invoke() to invoke a class method and are > obtaining the resulting object just fine. > > however, for performance reasons we'd like to switch to using the 'unmanaged > thunks', which we did not get to work. our call differes from the example in > the 'embedding mono' docs by the parameters and the fact that we are calling > a class method. however we try, just different crashes. > > > the function we have to call has this prototype: > public static string ParseToJSON(string input) > > which seems to translate to a mono method description of > XLParser.ExcelFormulaParser:ParseToJSON (string) > > we have no problem using mono_runtime_invoke() to call it exactly like this: > > > MonoAssembly *assembly = mono_domain_assembly_open(domain, > "/path/to/XLParser.dll"); > MonoImage *image = mono_assembly_get_image(assembly); > MonoClass *classHandle = mono_class_from_name(image, "XLParser", > "ExcelFormulaParser"); > const char *descAsString = "XLParser.ExcelFormulaParser:ParseToJSON > (string)"; > MonoMethodDesc *description = mono_method_desc_new(descAsString, 0); > method = mono_method_desc_search_in_class(description, classHandle); > void *args[1] = {mono_string_new (domain, "A+B")}; > MonoObject *resultObject = mono_runtime_invoke(method, NULL, args, NULL); > MonoString *resultString = mono_object_to_string(resultObject, NULL); > char *resultCString = mono_string_to_utf8(resultString); > > > now we are trying the thunk method: > > typedef MonoObject* (*ParseToJSON) (MonoString *obj1,MonoString *obj2); > ParseToJSON func = mono_method_get_unmanaged_thunk(method); > MonoString *s = mono_string_new (domain, "A+B"); > MonoObject *result = func(s,NULL); > MonoString *resultstring = mono_object_to_string(result, NULL); > char *str = mono_string_to_utf8(resultstring); > > but it crashes - any idea how to call a class method via thunks? > > > > > -- > View this message in context: > http://mono.1490590.n4.nabble.com/embedding-moving-from-mono-runtime-invoke-to-mono-method-get-unmanaged-thunk-or-how-to-call-class-me-tp4666935.html > Sent from the Mono - General mailing list archive at Nabble.com. > _______________________________________________ > Mono-list maillist - Mono-list@lists.ximian.com > http://lists.ximian.com/mailman/listinfo/mono-list > _______________________________________________ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list