Merge pull request #498 from Unroll-Me/master
[mono.git] / mcs / class / System.Configuration / System.Configuration / ConfigurationSection.cs
index 392478d2c2f67b4d2b64641d908541575f61c0fb..84723f85aa5e8ae7698f977578ee6ca21c7e28cd 100644 (file)
@@ -134,6 +134,7 @@ namespace System.Configuration
                {
                        ConfigurationElement elem = (ConfigurationElement) Activator.CreateInstance (t);
                        elem.Init ();
+                       elem.Configuration = Configuration;
                        if (IsReadOnly ())
                                elem.SetReadOnly ();
                        return elem;
@@ -186,7 +187,14 @@ namespace System.Configuration
                [MonoInternalNote ("find the proper location for the decryption stuff")]
                protected internal virtual void DeserializeSection (XmlReader reader)
                {
-                       DoDeserializeSection (reader);
+                       try
+                       {
+                               DoDeserializeSection (reader);
+                       }
+                       catch (ConfigurationErrorsException ex)
+                       {
+                               throw new ConfigurationErrorsException(String.Format("Error deserializing configuration section {0}: {1}", this.SectionInformation.Name, ex.Message));
+                       }
                }
 
                internal void DeserializeConfigSource (string basePath)
@@ -197,16 +205,16 @@ namespace System.Configuration
                                return;
 
                        if (Path.IsPathRooted (config_source))
-                               throw new ConfigurationException ("The configSource attribute must be a relative physical path.");
+                               throw new ConfigurationErrorsException ("The configSource attribute must be a relative physical path.");
                        
                        if (HasLocalModifications ())
-                               throw new ConfigurationException ("A section using 'configSource' may contain no other attributes or elements.");
+                               throw new ConfigurationErrorsException ("A section using 'configSource' may contain no other attributes or elements.");
                        
                        string path = Path.Combine (basePath, config_source);
                        if (!File.Exists (path)) {
                                RawXml = null;
                                SectionInformation.SetRawXml (null);
-                               return;
+                               throw new ConfigurationErrorsException (string.Format ("Unable to open configSource file '{0}'.", path));
                        }
                        
                        RawXml = File.ReadAllText (path);