Skip to content

Commit

Permalink
Fix #560060 - Embedded "app.config" is not read when used inside a bu…
Browse files Browse the repository at this point in the history
…ndle.

	* 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.
  • Loading branch information
letiemble authored and vargaz committed Aug 9, 2010
1 parent d87fc19 commit 0f1b1c1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
Expand Up @@ -166,6 +166,9 @@ public virtual bool IsTrustedConfigPath (string configPath)
#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)
Expand All @@ -180,6 +183,16 @@ public virtual Stream OpenStreamForRead (string streamName)
#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;

Expand Down
3 changes: 2 additions & 1 deletion mono/metadata/icall-def.h
Expand Up @@ -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 )
Expand Down
34 changes: 34 additions & 0 deletions mono/metadata/icall.c
Expand Up @@ -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)
{
Expand Down

0 comments on commit 0f1b1c1

Please sign in to comment.