[Mono-dev] Crash running C code built on OS X El Capitan in Xcode 7

Jonathan Mitchell jonathan at mugginsoft.com
Mon Nov 2 14:37:50 UTC 2015

The following C test code calls the current Mono 4.2.1-91 framework.
It builds and runs fine within Xcode 6.4 on 10.10.

It fails if I build and run it on OS X 10.11 using Xcode 7.1 - EXC_BAD_ACCESS in mono_jit_runtime_invoke() when calling AssemblyName:GetName()
However the built binary runs fine outside of the Xcode environment.

This obviously makes life difficult.
It seems logical to infer that the Xcode IDE is the issue here and I have posted to the Xcode list.

However, maybe there is more to this than I can detect.
Perhaps the code below is somehow suspect.
Any comments would be appreciated.


// Link against both Mono and CoreFoundation.
// Header search path set to /Library/Frameworks/Mono.framework/Headers/Mono-2.0
// Architecture i386.
#include <stdio.h>
#import <mono/jit/jit.h>
#import <mono/metadata/metadata.h>
#import <mono/metadata/debug-helpers.h>

MonoObject *invokeName(MonoObject *object, char *name);

int main(int argc, const char * argv[]) {

   // init
   MonoDomain *domain = mono_jit_init_version("Dubrovnik", "v4.0.30319");
   MonoAssembly *assembly = mono_domain_assembly_open(domain, "mscorlib");

   // returns System.Reflection.Assembly
   MonoReflectionAssembly *assemblyObject = mono_assembly_get_object(domain, assembly);

   // returns System.Reflection.AssemblyName
   MonoObject *assemblyNameObject = invokeName((MonoObject *)assemblyObject, ":GetName()");

   // returns System.Version
   MonoObject *versionObject = invokeName(assemblyNameObject, ":get_Version()");

   // Returns System.String
   MonoObject *stringObject = invokeName(versionObject, ":ToString()");
   printf("Version : %s\n", mono_string_to_utf8((MonoString *)stringObject));

   return 0;

MonoObject *invokeName(MonoObject *object, char *name)
   MonoClass *klass = mono_object_get_class(object);

   MonoMethodDesc *methodDesc = mono_method_desc_new(name, 1);
   MonoMethod *meth = NULL;
   while (klass != NULL) {
       meth = mono_method_desc_search_in_class(methodDesc, klass);
       if(meth != NULL) {
           meth = mono_object_get_virtual_method(object, meth);
       klass = mono_class_get_parent(klass);
   MonoObject *monoException = NULL;
   MonoObject *resultObject = mono_runtime_invoke(meth, object, NULL, &monoException);

   klass = mono_object_get_class(resultObject);
   printf("invokeName returned : %s\n", mono_class_get_name(klass));

   return resultObject;

Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (Xcode-users at lists.apple.com)
Help/Unsubscribe/Update your Subscription:

This email sent to jonathan at mugginsoft.com

More information about the Mono-devel-list mailing list