An issue we ran into when embedding mono into another program was that
the configuration file of the application domain wasn't being
initialized, so accessing that later (i.e., stuff in
ConfigurationManager) would cause a null pointer dereference.

I'll attach the patch we're using to fix this; it adds some setup
stuff to mini_init to ensure this gets initialized. Let me know if
this function isn't the right place for these.

This patch is against SVN revision 113069 of the mono-2-0 branch.

Thanks
Index: mono/mini/mini.c
===================================================================
--- mono/mini/mini.c	(revision 113069)
+++ mono/mini/mini.c	(working copy)
@@ -14265,6 +14265,33 @@
 	register_icall (mono_array_new_2, "mono_array_new_2", "object ptr int int", FALSE);
 #endif
 
+	// Create the domain setup - this is normally done in the non embedded
+	// case, but appears to be missing for the embedded mono.
+	if(!domain->setup) {
+	  	MonoClass *class = mono_class_from_name 
+		  (mono_defaults.corlib, 
+		   "System", 
+		   "AppDomainSetup");
+		domain->setup = (MonoAppDomainSetup *) mono_object_new (domain, class);
+	}
+
+	/* Initialize this to a reasonable value, so embedded mono works.
+	   Without this, we dereference a NULL pointer in
+	   ConfigurationManager.OpenExeConfigurationInternal */
+	if (domain->setup->configuration_file == NULL) {
+	        gchar *basename = g_path_get_basename(filename);
+		gchar *str = g_strconcat (basename, ".config", NULL);
+		MONO_OBJECT_SETREF (domain->setup, configuration_file, mono_string_new (domain, str));
+		g_free (str);
+		g_free(basename);
+	}
+
+	if (domain->setup->application_base == NULL) {
+	  gchar *dirname = g_path_get_dirname(filename);
+	  MONO_OBJECT_SETREF (domain->setup, application_base, mono_string_new (domain, dirname));
+	  g_free(dirname);
+	}
+
 	mono_generic_sharing_init ();
 
 	if (mono_compile_aot)
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to