84995699644da2e6a0c772dce44603824e96d8ca
[mono.git] / mcs / class / System / System.Configuration / ConfigurationSettings.cs
1 //
2 // System.Configuration.ConfigurationSettings.cs
3 //
4 // Author:
5 //   Christopher Podurgiel (cpodurgiel@msn.com)
6 //   Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 //   Eric Lindvall (eric@5stops.com)
8 //
9 // (c) Christopher Podurgiel
10 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
11 // (c) 2003 Novell, Inc. (http://www.novell.com)
12 //
13
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 #if CONFIGURATION_DEP && !TARGET_JVM
36 extern alias PrebuiltSystem;
37 using NameValueCollection = PrebuiltSystem.System.Collections.Specialized.NameValueCollection;
38 #endif
39
40 using System;
41 using System.Collections;
42 using System.Collections.Specialized;
43 using System.IO;
44 using System.Runtime.CompilerServices;
45 using System.Security.Permissions;
46 #if (XML_DEP)
47 using System.Xml;
48 using System.Xml.XPath;
49 #endif
50 #if TARGET_JVM
51 using vmw.common;
52 using vmw.@internal.io;
53 #endif
54
55 namespace System.Configuration
56 {
57         public sealed class ConfigurationSettings
58         {
59 #if !TARGET_JVM
60                 static IConfigurationSystem config = DefaultConfig.GetInstance ();
61 #else
62                 static IConfigurationSystem config {
63                         get {
64                                 IConfigurationSystem conf = (IConfigurationSystem) AppDomain.CurrentDomain.GetData ("ConfigurationSettings.Config");
65                                 if (conf == null) {
66                                         conf = DefaultConfig.GetInstance ();
67                                         AppDomain.CurrentDomain.SetData ("ConfigurationSettings.Config", conf);
68                                 }
69                                 return conf;
70                         }
71                         set {
72                                 AppDomain.CurrentDomain.SetData ("ConfigurationSettings.Config", value);
73                         }
74                 }
75 #endif
76                 static object lockobj = new object ();
77                 private ConfigurationSettings ()
78                 {
79                 }
80
81                 [Obsolete ("This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.GetSection")]
82                 public static object GetConfig (string sectionName)
83                 {
84 #if CONFIGURATION_DEP
85                         return ConfigurationManager.GetSection (sectionName);
86 #else
87                         return config.GetConfig (sectionName);
88 #endif
89                 }
90
91                 [Obsolete ("This property is obsolete.  Please use System.Configuration.ConfigurationManager.AppSettings")]
92                 public static NameValueCollection AppSettings
93                 {
94                         get {
95 #if CONFIGURATION_DEP
96                                 object appSettings = ConfigurationManager.GetSection ("appSettings");
97 #else
98                                 object appSettings = GetConfig ("appSettings");
99 #endif
100                                 if (appSettings == null)
101                                         appSettings = new NameValueCollection ();
102                                 return (NameValueCollection) appSettings;
103                         }
104                 }
105
106                 // Invoked from System.Web, disable warning
107                 internal static IConfigurationSystem ChangeConfigurationSystem (IConfigurationSystem newSystem)
108                 {
109                         if (newSystem == null)
110                                 throw new ArgumentNullException ("newSystem");
111
112                         lock (lockobj) {
113                                 IConfigurationSystem old = config;
114                                 config = newSystem;
115                                 return old;
116                         }
117                 }
118         }
119
120         //
121         // class DefaultConfig: read configuration from machine.config file and application
122         // config file if available.
123         //
124         class DefaultConfig : IConfigurationSystem
125         {
126 #if !TARGET_JVM
127                 static readonly DefaultConfig instance = new DefaultConfig ();        
128 #else
129                 static DefaultConfig instance {
130                         get {
131                                 DefaultConfig conf = (DefaultConfig) AppDomain.CurrentDomain.GetData ("DefaultConfig.instance");
132                                 if (conf == null) {
133                                         conf = new DefaultConfig ();
134                                         AppDomain.CurrentDomain.SetData ("DefaultConfig.instance", conf);
135                                 }
136                                 return conf;
137                         }
138                         set {
139                                 AppDomain.CurrentDomain.SetData ("DefaultConfig.instance", value);
140                         }
141                 }
142 #endif
143                 ConfigurationData config;
144                 
145                 private DefaultConfig ()
146                 {
147                 }
148
149                 public static DefaultConfig GetInstance ()
150                 {
151                         return instance;
152                 }
153
154                 [Obsolete ("This method is obsolete.  Please use System.Configuration.ConfigurationManager.GetConfig")]
155                 public object GetConfig (string sectionName)
156                 {
157                         Init ();
158                         return config.GetConfig (sectionName);
159                 }
160
161                 public void Init ()
162                 {
163                         lock (this) {
164                                 if (config != null)
165                                         return;
166
167                                 ConfigurationData data = new ConfigurationData ();
168                                 if (data.LoadString (GetBundledMachineConfig ())) {
169                                         // do nothing
170                                 } else {
171                                         if (!data.Load (GetMachineConfigPath ()))
172                                                 throw new ConfigurationException ("Cannot find " + GetMachineConfigPath ());
173
174                                 }
175                                 string appfile = GetAppConfigPath ();
176                                 if (appfile == null) {
177                                         config = data;
178                                         return;
179                                 }
180
181                                 ConfigurationData appData = new ConfigurationData (data);
182                                 if (appData.Load (appfile))
183                                         config = appData;
184                                 else
185                                         config = data;
186                         }
187                 }
188 #if TARGET_JVM
189                 internal static string GetBundledMachineConfig ()
190                 {
191                         return null;
192                 }
193                 internal static string GetMachineConfigPath ()
194                 {
195                         return System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile;
196                 }
197 #else
198                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
199                 extern private static string get_bundled_machine_config ();
200                 internal static string GetBundledMachineConfig ()
201                 {
202                         return get_bundled_machine_config ();
203                 }
204                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
205                 extern private static string get_machine_config_path ();
206                 internal static string GetMachineConfigPath ()
207                 {
208                         return get_machine_config_path ();
209                 }
210 #endif
211                 private static string GetAppConfigPath ()
212                 {
213                         AppDomainSetup currentInfo = AppDomain.CurrentDomain.SetupInformation;
214
215                         string configFile = currentInfo.ConfigurationFile;
216                         if (configFile == null || configFile.Length == 0)
217                                 return null;
218
219                         return configFile;
220
221                 }
222         }
223
224         enum AllowDefinition
225         {
226                 Everywhere,
227                 MachineOnly,
228                 MachineToApplication
229         }
230
231         class SectionData
232         {
233                 public readonly string SectionName;
234                 public readonly string TypeName;
235                 public readonly bool AllowLocation;
236                 public readonly AllowDefinition AllowDefinition;
237 #if XML_DEP
238                 public string FileName;
239 #endif
240                 public readonly bool RequirePermission;
241
242                 public SectionData (string sectionName, string typeName,
243                             bool allowLocation, AllowDefinition allowDefinition, bool requirePermission)
244                 {
245                         SectionName = sectionName;
246                         TypeName = typeName;
247                         AllowLocation = allowLocation;
248                         AllowDefinition = allowDefinition;
249                         RequirePermission = requirePermission;
250                 }
251         }
252
253
254         class ConfigurationData
255         {
256                 ConfigurationData parent;
257                 Hashtable factories;
258                 static object removedMark = new object ();
259                 static object emptyMark = new object ();
260 #if (XML_DEP)
261                 Hashtable pending;
262                 string fileName;
263                 static object groupMark = new object ();
264 #endif
265                 Hashtable cache;
266
267                 Hashtable FileCache {
268                         get {
269                                 if (cache != null)
270                                         return cache;
271
272                                 cache = new Hashtable ();
273                                 return cache;
274                         }
275                 }
276
277                 public ConfigurationData () : this (null)
278                 {
279                 }
280
281                 public ConfigurationData (ConfigurationData parent)
282                 {
283                         this.parent = (parent == this) ? null : parent;
284                         factories = new Hashtable ();
285                 }
286
287                 // SECURITY-FIXME: limit this with an imperative assert for reading the specific file
288                 [FileIOPermission (SecurityAction.Assert, Unrestricted = true)]
289                 public bool Load (string fileName)
290                 {
291 #if (XML_DEP)
292                         this.fileName = fileName;
293                         if (fileName == null
294 #if !TARGET_JVM
295                                 || !File.Exists (fileName)
296 #endif
297 )
298                                 return false;
299                         
300                         XmlTextReader reader = null;
301
302                         try {
303 #if !TARGET_JVM
304                                 FileStream fs = new FileStream (fileName, FileMode.Open, FileAccess.Read);
305 #else
306                                 Stream fs = (Stream) vmw.common.IOUtils.getStream (fileName);
307
308                                 //patch for machine.config
309                                 if (fs == null && fileName.EndsWith ("machine.config")) {
310                                         fs = (Stream) IOUtils.getStreamForGHConfigs (fileName);
311                                 }
312
313                                 if (fs == null) {
314                                         return false;
315                                 }
316 #endif
317                                 reader = new XmlTextReader (fs);
318                                 if (InitRead (reader))
319                                         ReadConfigFile (reader);
320                         } catch (ConfigurationException) {
321                                 throw;
322                         } catch (Exception e) {
323                                 throw new ConfigurationException ("Error reading " + fileName, e);
324                         } finally {
325                                 if (reader != null)
326                                         reader.Close();
327                         }
328 #endif
329                         return true;
330                 }
331                 
332                 public bool LoadString (string data)
333                 {
334                         if (data == null)
335                                 return false;
336 #if (XML_DEP)
337                         XmlTextReader reader = null;
338
339                         try {
340                                 TextReader tr = new StringReader (data);
341                                 reader = new XmlTextReader (tr);
342                                 if (InitRead (reader))
343                                         ReadConfigFile (reader);
344                         } catch (ConfigurationException) {
345                                 throw;
346                         } catch (Exception e) {
347                                 throw new ConfigurationException ("Error reading " + fileName, e);
348                         } finally {
349                                 if (reader != null)
350                                         reader.Close();
351                         }
352 #endif
353                         return true;
354                 }
355                 
356                 object GetHandler (string sectionName)
357                 {
358                         lock (factories) {
359                                 object o = factories [sectionName];
360                                 if (o == null || o == removedMark) {
361                                         if (parent != null)
362                                                 return parent.GetHandler (sectionName);
363
364                                         return null;
365                                 }
366
367                                 if (o is IConfigurationSectionHandler)
368                                         return (IConfigurationSectionHandler) o;
369
370                                 o = CreateNewHandler (sectionName, (SectionData) o);
371                                 factories [sectionName] = o;
372                                 return o;
373                         }
374                 }
375
376                 object CreateNewHandler (string sectionName, SectionData section)
377                 {
378                         Type t = Type.GetType (section.TypeName);
379                         if (t == null)
380                                 throw new ConfigurationException ("Cannot get Type for " + section.TypeName);
381
382 #if false
383                         Type iconfig = typeof (IConfigurationSectionHandler);
384                         if (!iconfig.IsAssignableFrom (t))
385                                 throw new ConfigurationException (sectionName + " does not implement " + iconfig);
386 #endif
387                         
388                         object o = Activator.CreateInstance (t, true);
389                         if (o == null)
390                                 throw new ConfigurationException ("Cannot get instance for " + t);
391
392                         return o;
393                 }
394 #if (XML_DEP)
395                 XmlDocument GetInnerDoc (XmlDocument doc, int i, string [] sectionPath)
396                 {
397                         if (++i >= sectionPath.Length)
398                                 return doc;
399
400                         if (doc.DocumentElement == null)
401                                 return null;
402
403                         XmlNode node = doc.DocumentElement.FirstChild;
404                         while (node != null) {
405                                 if (node.Name == sectionPath [i]) {
406                                         ConfigXmlDocument result = new ConfigXmlDocument ();
407                                         result.Load (new StringReader (node.OuterXml));
408                                         return GetInnerDoc (result, i, sectionPath);
409                                 }
410                                 node = node.NextSibling;
411                         }
412
413                         return null;
414                 }
415
416                 XmlDocument GetDocumentForSection (string sectionName)
417                 {
418                         ConfigXmlDocument doc = new ConfigXmlDocument ();
419                         if (pending == null)
420                                 return doc;
421
422                         string [] sectionPath = sectionName.Split ('/');
423                         string outerxml = pending [sectionPath [0]] as string;
424                         if (outerxml == null)
425                                 return doc;
426
427                         StringReader reader = new StringReader (outerxml);
428                         XmlTextReader rd = new XmlTextReader (reader);
429                         rd.MoveToContent ();
430                         doc.LoadSingleElement (fileName, rd);
431
432                         return GetInnerDoc (doc, 0, sectionPath);
433                 }
434                 
435                 object GetConfigInternal (string sectionName)
436                 {
437                         object handler = GetHandler (sectionName);
438                         IConfigurationSectionHandler iconf = handler as IConfigurationSectionHandler;
439                         if (iconf == null)
440                                 return handler;
441
442                         object parentConfig = null;
443                         if (parent != null)
444                                 parentConfig = parent.GetConfig (sectionName);
445
446                         XmlDocument doc = GetDocumentForSection (sectionName);
447                         if (doc == null || doc.DocumentElement == null)
448                                 return parentConfig;
449                         
450                         return iconf.Create (parentConfig, fileName, doc.DocumentElement);
451                 }
452 #else
453                 object GetConfigInternal (string sectionName)
454                 {
455                     return null;
456                 }
457 #endif
458                 public object GetConfig (string sectionName)
459                 {
460                         object config;
461                         lock (this) {
462                                 config = this.FileCache [sectionName];
463                         }
464
465                         if (config == emptyMark)
466                                 return null;
467
468                         if (config != null)
469                                 return config;
470
471                         lock (this) {
472                                 config = GetConfigInternal (sectionName);
473                                 this.FileCache [sectionName] = (config == null) ? emptyMark : config;
474                         }
475
476                         return config;
477                 }
478
479                 private object LookForFactory (string key)
480                 {
481                         object o = factories [key];
482                         if (o != null)
483                                 return o;
484
485                         if (parent != null)
486                                 return parent.LookForFactory (key);
487
488                         return null;
489                 }
490 #if (XML_DEP)
491                 private bool InitRead (XmlTextReader reader)
492                 {
493                         reader.MoveToContent ();
494                         if (reader.NodeType != XmlNodeType.Element || reader.Name != "configuration")
495                                 ThrowException ("Configuration file does not have a valid root element", reader);
496
497                         if (reader.HasAttributes)
498                                 ThrowException ("Unrecognized attribute in root element", reader);
499                         if (reader.IsEmptyElement) {
500                                 reader.Skip ();
501                                 return false;
502                         }
503                         reader.Read ();
504                         reader.MoveToContent ();
505                         return reader.NodeType != XmlNodeType.EndElement;
506                 }
507
508                 // FIXME: this approach is not always safe and likely to cause bugs.
509                 private void MoveToNextElement (XmlTextReader reader)
510                 {
511                         while (reader.Read ()) {
512                                 XmlNodeType ntype = reader.NodeType;
513                                 if (ntype == XmlNodeType.Element)
514                                         return;
515
516                                 if (ntype != XmlNodeType.Whitespace &&
517                                     ntype != XmlNodeType.Comment &&
518                                     ntype != XmlNodeType.SignificantWhitespace &&
519                                     ntype != XmlNodeType.EndElement)
520                                         ThrowException ("Unrecognized element", reader);
521                         }
522                 }
523
524                 private void ReadSection (XmlTextReader reader, string sectionName)
525                 {
526                         string attName;
527                         string nameValue = null;
528                         string typeValue = null;
529                         string allowLoc = null, allowDef = null;
530                         bool requirePermission = false;
531                         string requirePer = null;
532                         bool allowLocation = true;
533                         AllowDefinition allowDefinition = AllowDefinition.Everywhere;
534
535                         while (reader.MoveToNextAttribute ()) {
536                                 attName = reader.Name;
537                                 if (attName == null)
538                                         continue;
539
540                                 if (attName == "allowLocation") {
541                                         if (allowLoc != null)
542                                                 ThrowException ("Duplicated allowLocation attribute.", reader);
543
544                                         allowLoc = reader.Value;
545                                         allowLocation = (allowLoc == "true");
546                                         if (!allowLocation && allowLoc != "false")
547                                                 ThrowException ("Invalid attribute value", reader);
548
549                                         continue;
550                                 }
551
552                                 if (attName == "requirePermission") {
553                                         if (requirePer != null)
554                                                 ThrowException ("Duplicated requirePermission attribute.", reader);
555                                         requirePer = reader.Value;
556                                         requirePermission = (requirePer == "true");
557                                         if (!requirePermission && requirePer != "false")
558                                                 ThrowException ("Invalid attribute value", reader);
559                                         continue;
560                                 }
561
562                                 if (attName == "allowDefinition") {
563                                         if (allowDef != null)
564                                                 ThrowException ("Duplicated allowDefinition attribute.", reader);
565
566                                         allowDef = reader.Value;
567                                         try {
568                                                 allowDefinition = (AllowDefinition) Enum.Parse (
569                                                                    typeof (AllowDefinition), allowDef);
570                                         } catch {
571                                                 ThrowException ("Invalid attribute value", reader);
572                                         }
573
574                                         continue;
575                                 }
576
577                                 if (attName == "type")  {
578                                         if (typeValue != null)
579                                                 ThrowException ("Duplicated type attribute.", reader);
580                                         typeValue = reader.Value;
581                                         continue;
582                                 }
583                                 
584                                 if (attName == "name")  {
585                                         if (nameValue != null)
586                                                 ThrowException ("Duplicated name attribute.", reader);
587                                         nameValue = reader.Value;
588                                         if (nameValue == "location")
589                                                 ThrowException ("location is a reserved section name", reader);
590                                         continue;
591                                 }
592
593                                 ThrowException ("Unrecognized attribute.", reader);
594                         }
595
596                         if (nameValue == null || typeValue == null)
597                                 ThrowException ("Required attribute missing", reader);
598
599                         if (sectionName != null)
600                                 nameValue = sectionName + '/' + nameValue;
601
602                         reader.MoveToElement();
603                         object o = LookForFactory (nameValue);
604                         if (o != null && o != removedMark)
605                                 ThrowException ("Already have a factory for " + nameValue, reader);
606                         SectionData section = new SectionData (nameValue, typeValue, allowLocation,
607                                 allowDefinition, requirePermission);
608                         section.FileName = fileName;
609                         factories [nameValue] = section;
610
611                         if (reader.IsEmptyElement)
612                                 reader.Skip ();
613                         else {
614                                 reader.Read ();
615                                 reader.MoveToContent ();
616                                 if (reader.NodeType != XmlNodeType.EndElement)
617                                         // sub-section inside a section
618                                         ReadSections (reader, nameValue);
619                                 reader.ReadEndElement ();
620                         }
621                         reader.MoveToContent ();
622                 }
623
624                 private void ReadRemoveSection (XmlTextReader reader, string sectionName)
625                 {
626                         if (!reader.MoveToNextAttribute () || reader.Name != "name")
627                                 ThrowException ("Unrecognized attribute.", reader);
628
629                         string removeValue = reader.Value;
630                         if (removeValue == null || removeValue.Length == 0)
631                                 ThrowException ("Empty name to remove", reader);
632
633                         reader.MoveToElement ();
634
635                         if (sectionName != null)
636                                 removeValue = sectionName + '/' + removeValue;
637
638                         object o = LookForFactory (removeValue);
639                         if (o != null && o == removedMark)
640                                 ThrowException ("No factory for " + removeValue, reader);
641
642                         factories [removeValue] = removedMark;
643                         MoveToNextElement (reader);
644                 }
645
646                 private void ReadSectionGroup (XmlTextReader reader, string configSection)
647                 {
648                         if (!reader.MoveToNextAttribute ())
649                                 ThrowException ("sectionGroup must have a 'name' attribute.", reader);
650
651                         string value = null;
652                         do {
653                                 if (reader.Name == "name") {
654                                         if (value != null)
655                                                 ThrowException ("Duplicate 'name' attribute.", reader);
656                                         value = reader.Value;
657                                 }
658                                 else
659                                 if (reader.Name != "type")
660                                         ThrowException ("Unrecognized attribute.", reader);
661                         } while (reader.MoveToNextAttribute ());
662
663                         if (value == null)
664                                 ThrowException ("No 'name' attribute.", reader);
665                         
666                         if (value == "location")
667                                 ThrowException ("location is a reserved section name", reader);
668
669                         if (configSection != null)
670                                 value = configSection + '/' + value;
671
672                         object o = LookForFactory (value);
673                         if (o != null && o != removedMark && o != groupMark)
674                                 ThrowException ("Already have a factory for " + value, reader);
675
676                         factories [value] = groupMark;
677
678                         if (reader.IsEmptyElement) {
679                                 reader.Skip ();
680                                 reader.MoveToContent ();
681                         } else {
682                                 reader.Read ();
683                                 reader.MoveToContent ();
684                                 if (reader.NodeType != XmlNodeType.EndElement)
685                                         ReadSections (reader, value);
686                                 reader.ReadEndElement ();
687                                 reader.MoveToContent ();
688                         }
689                 }
690
691                 // It stops XmlReader consumption at where it found
692                 // surrounding EndElement i.e. EndElement is not consumed here
693                 private void ReadSections (XmlTextReader reader, string configSection)
694                 {
695                         int depth = reader.Depth;
696                         for (reader.MoveToContent ();
697                              reader.Depth == depth;
698                              reader.MoveToContent ()) {
699                                 string name = reader.Name;
700                                 if (name == "section") {
701                                         ReadSection (reader, configSection);
702                                         continue;
703                                 } 
704                                 
705                                 if (name == "remove") {
706                                         ReadRemoveSection (reader, configSection);
707                                         continue;
708                                 }
709
710                                 if (name == "clear") {
711                                         if (reader.HasAttributes)
712                                                 ThrowException ("Unrecognized attribute.", reader);
713
714                                         factories.Clear ();
715                                         MoveToNextElement (reader);
716                                         continue;
717                                 }
718
719                                 if (name == "sectionGroup") {
720                                         ReadSectionGroup (reader, configSection);
721                                         continue;
722                                 }
723                                 
724
725                                 ThrowException ("Unrecognized element: " + reader.Name, reader);
726                         }
727                 }
728
729                 void StorePending (string name, XmlTextReader reader)
730                 {
731                         if (pending == null)
732                                 pending = new Hashtable ();
733
734                         pending [name] = reader.ReadOuterXml ();
735                 }
736
737                 private void ReadConfigFile (XmlTextReader reader)
738                 {
739                         //int depth = reader.Depth;
740                         for (reader.MoveToContent ();
741                              !reader.EOF && reader.NodeType != XmlNodeType.EndElement;
742                              reader.MoveToContent ()) {
743                                 string name = reader.Name;
744                                 if (name == "configSections") {
745                                         if (reader.HasAttributes)
746                                                 ThrowException ("Unrecognized attribute in <configSections>.", reader);
747                                         if (reader.IsEmptyElement)
748                                                 reader.Skip ();
749                                         else {
750                                                 reader.Read ();
751                                                 reader.MoveToContent ();
752                                                 if (reader.NodeType != XmlNodeType.EndElement)
753                                                         ReadSections (reader, null);
754                                                 reader.ReadEndElement ();
755                                         }
756                                 } else if (name != null && name != "") {
757                                         StorePending (name, reader);
758                                         MoveToNextElement (reader);
759                                 } else {
760                                         MoveToNextElement (reader);
761                                 }
762                         }
763                 }
764                 
765                 private void ThrowException (string text, XmlTextReader reader)
766                 {
767                         throw new ConfigurationException (text, fileName, reader.LineNumber);
768                 }
769 #endif
770         }
771 }
772
773