Merge pull request #3715 from kumpera/fix-44707
authorRodrigo Kumpera <kumpera@users.noreply.github.com>
Tue, 11 Oct 2016 18:31:04 +0000 (14:31 -0400)
committerGitHub <noreply@github.com>
Tue, 11 Oct 2016 18:31:04 +0000 (14:31 -0400)
[corlib] Don't load the machine config file if it's missing. Fixes #44707

mcs/class/corlib/System.Runtime.Remoting/RemotingConfiguration.cs
mcs/class/corlib/System/Environment.cs
mono/metadata/icall-def.h

index 33fef7a0a8d2c26525bdb5146ef1093305ae47d7..eb45ced8220104fedb88ee88eb5f57c6af55be7f 100644 (file)
@@ -106,7 +106,12 @@ namespace System.Runtime.Remoting
                {
                        lock (channelTemplates) {
                                if (!defaultConfigRead) {
-                                       ReadConfigFile (Environment.GetMachineConfigPath ());
+                                       var bundled = Environment.GetBundledMachineConfig ();
+                                       if (bundled != null)
+                                               ReadConfigString (bundled);
+
+                                       if (File.Exists (Environment.GetMachineConfigPath ()))
+                                               ReadConfigFile (Environment.GetMachineConfigPath ());
                                        defaultConfigRead = true;
                                }
 
@@ -121,6 +126,22 @@ namespace System.Runtime.Remoting
                        Configure (filename, false);
                }
 
+               private static void ReadConfigString (string filename)
+               {
+                       try
+                       {
+                               SmallXmlParser parser = new SmallXmlParser ();
+                               using (TextReader rreader = new StringReader (filename)) {
+                                       ConfigHandler handler = new ConfigHandler (false);
+                                       parser.Parse (rreader, handler);
+                               }
+                       }
+                       catch (Exception ex)
+                       {
+                               throw new RemotingException ("Configuration string could not be loaded: " + ex.Message, ex);
+                       }
+               }
+
                private static void ReadConfigFile (string filename)
                {
                        try
index 6411972d27f61017fb0ea343818bed4272cf3034..e8befe2e061e34dc9bd7fda7213c8b2c2f76c222 100644 (file)
@@ -996,6 +996,14 @@ namespace System {
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                internal extern static int GetPageSize ();
 
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern private static string get_bundled_machine_config ();
+
+               internal static string GetBundledMachineConfig ()
+               {
+                       return get_bundled_machine_config ();
+               }
+
                static internal bool IsUnix {
                        get {
                                int platform = (int) Environment.Platform;
index d47fd5c615f5ffe693ffda693df7904ad833d4eb..3825701be4418c3704d9ce6ad861a6116b59b300 100644 (file)
@@ -521,6 +521,7 @@ ICALL(ENV_13, "get_Platform", ves_icall_System_Environment_get_Platform)
 ICALL(ENV_14, "get_ProcessorCount", mono_cpu_count)
 ICALL(ENV_15, "get_TickCount", ves_icall_System_Environment_get_TickCount)
 ICALL(ENV_16, "get_UserName", ves_icall_System_Environment_get_UserName)
+HANDLES(ICALL(ENV_16b, "get_bundled_machine_config", get_bundled_machine_config))
 ICALL(ENV_16m, "internalBroadcastSettingChange", ves_icall_System_Environment_BroadcastSettingChange)
 HANDLES(ICALL(ENV_17, "internalGetEnvironmentVariable_native", ves_icall_System_Environment_GetEnvironmentVariable_native))
 HANDLES(ICALL(ENV_18, "internalGetGacPath", ves_icall_System_Environment_GetGacPath))