From 0f1b1c1988926772d50ccb131227a18ceebb62eb Mon Sep 17 00:00:00 2001 From: Laurent Etiemble Date: Mon, 9 Aug 2010 21:21:33 +0200 Subject: [PATCH] Fix #560060 - Embedded "app.config" is not read when used inside a bundle. * mcs/class/System.Configuration/System.Configuration/InternalConfigurationHost.cs: Add new internal call to retrieve embedded application config. First check if an embedded configuration exists before looking up on the filesystem. * mono/metadata/icall-def.h: Add entry for retrieving embedded application configuration. * mono/metadata/icall.c: Add function to retrieve embedded application configuration if one has been registered with the runtime. --- .../InternalConfigurationHost.cs | 13 +++++++ mono/metadata/icall-def.h | 3 +- mono/metadata/icall.c | 34 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/mcs/class/System.Configuration/System.Configuration/InternalConfigurationHost.cs b/mcs/class/System.Configuration/System.Configuration/InternalConfigurationHost.cs index b32eac21579..1219fcd9992 100644 --- a/mcs/class/System.Configuration/System.Configuration/InternalConfigurationHost.cs +++ b/mcs/class/System.Configuration/System.Configuration/InternalConfigurationHost.cs @@ -166,6 +166,9 @@ namespace System.Configuration #if !TARGET_JVM [MethodImplAttribute(MethodImplOptions.InternalCall)] extern private static string get_bundled_machine_config (); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + extern private static string get_bundled_app_config (); #endif public virtual Stream OpenStreamForRead (string streamName) @@ -180,6 +183,16 @@ namespace System.Configuration #endif } + if (String.CompareOrdinal (streamName, AppDomain.CurrentDomain.SetupInformation.ConfigurationFile) == 0) { +#if TARGET_JVM + throw new NotImplementedException(); +#else + string bundle = get_bundled_app_config (); + if (bundle != null) + return new MemoryStream (System.Text.Encoding.UTF8.GetBytes (bundle)); +#endif + } + if (!File.Exists (streamName)) return null; diff --git a/mono/metadata/icall-def.h b/mono/metadata/icall-def.h index d30c72a48aa..e387ca6e369 100644 --- a/mono/metadata/icall-def.h +++ b/mono/metadata/icall-def.h @@ -125,7 +125,8 @@ ICALL(DEFAULTC_2, "get_machine_config_path", ves_icall_System_Configuration_Defa /* Note that the below icall shares the same function as DefaultConfig uses */ ICALL_TYPE(INTCFGHOST, "System.Configuration.InternalConfigurationHost", INTCFGHOST_1) -ICALL(INTCFGHOST_1, "get_bundled_machine_config", get_bundled_machine_config) +ICALL(INTCFGHOST_1, "get_bundled_app_config", get_bundled_app_config) +ICALL(INTCFGHOST_2, "get_bundled_machine_config", get_bundled_machine_config) ICALL_TYPE(CONSOLE, "System.ConsoleDriver", CONSOLE_1) ICALL(CONSOLE_1, "InternalKeyAvailable", ves_icall_System_ConsoleDriver_InternalKeyAvailable ) diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index 07e25281a40..e6adb8c8566 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -6846,6 +6846,40 @@ ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void) return mcpath; } +static MonoString * +get_bundled_app_config (void) +{ + const gchar *app_config; + MonoDomain *domain; + MonoString *file; + gchar *config_file; + gsize len; + gchar *module; + + MONO_ARCH_SAVE_REGS; + + domain = mono_domain_get (); + file = domain->setup->configuration_file; + if (!file) + return NULL; + + // Retrieve config file and remove the extension + config_file = mono_string_to_utf8 (file); + len = strlen (config_file) - strlen (".config"); + module = g_malloc0 (len + 1); + memcpy (module, config_file, len); + // Get the config file from the module name + app_config = mono_config_string_for_assembly_file (module); + // Clean-up + g_free (module); + g_free (config_file); + + if (!app_config) + return NULL; + + return mono_string_new (mono_domain_get (), app_config); +} + static MonoString * get_bundled_machine_config (void) { -- 2.25.1