4e4ffc9e52454163a2fa7518f347e76ddbac9ae0
[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 #if NET_2_0
82                 [Obsolete ("This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.GetSection")]
83 #endif
84                 public static object GetConfig (string sectionName)
85                 {
86                         return config.GetConfig (sectionName);
87                 }
88
89 #if NET_2_0
90                 [Obsolete ("This property is obsolete.  Please use System.Configuration.ConfigurationManager.AppSettings")]
91 #endif
92                 public static NameValueCollection AppSettings
93                 {
94                         get {
95 #if NET_2_0 && 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 #if NET_2_0
155                 [Obsolete ("This method is obsolete.  Please use System.Configuration.ConfigurationManager.GetConfig")]
156 #endif
157                 public object GetConfig (string sectionName)
158                 {
159                         Init ();
160                         return config.GetConfig (sectionName);
161                 }
162
163                 public void Init ()
164                 {
165                         lock (this) {
166                                 if (config != null)
167                                         return;
168
169                                 ConfigurationData data = new ConfigurationData ();
170                                 if (data.LoadString (GetBundledMachineConfig ())) {
171                                         // do nothing
172                                 } else {
173                                         if (!data.Load (GetMachineConfigPath ()))
174                                                 throw new ConfigurationException ("Cannot find " + GetMachineConfigPath ());
175
176                                 }
177                                 string appfile = GetAppConfigPath ();
178                                 if (appfile == null) {
179                                         config = data;
180                                         return;
181                                 }
182
183                                 ConfigurationData appData = new ConfigurationData (data);
184                                 if (appData.Load (appfile))
185                                         config = appData;
186                                 else
187                                         config = data;
188                         }
189                 }
190
191                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
192                 extern private static string get_bundled_machine_config ();
193                 internal static string GetBundledMachineConfig ()
194                 {
195                         return get_bundled_machine_config ();
196                 }
197 #if TARGET_JVM
198                 internal static string GetMachineConfigPath ()
199                 {
200                         return "/machine.config";
201                 }
202 #else
203                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
204                 extern private static string get_machine_config_path ();
205                 internal static string GetMachineConfigPath ()
206                 {
207                         return get_machine_config_path ();
208                 }
209 #endif
210                 private static string GetAppConfigPath ()
211                 {
212                         AppDomainSetup currentInfo = AppDomain.CurrentDomain.SetupInformation;
213
214                         string configFile = currentInfo.ConfigurationFile;
215                         if (configFile == null || configFile.Length == 0)
216                                 return null;
217
218                         return configFile;
219
220                 }
221         }
222
223         enum AllowDefinition
224         {
225                 Everywhere,
226                 MachineOnly,
227                 MachineToApplication
228         }
229
230         class SectionData
231         {
232                 public readonly string SectionName;
233                 public readonly string TypeName;
234                 public readonly bool AllowLocation;
235                 public readonly AllowDefinition AllowDefinition;
236                 public string FileName;
237                 public readonly bool RequirePermission;
238
239                 public SectionData (string sectionName, string typeName,
240                             bool allowLocation, AllowDefinition allowDefinition, bool requirePermission)
241                 {
242                         SectionName = sectionName;
243                         TypeName = typeName;
244                         AllowLocation = allowLocation;
245                         AllowDefinition = allowDefinition;
246                         RequirePermission = requirePermission;
247                 }
248         }
249
250
251         class ConfigurationData
252         {
253                 ConfigurationData parent;
254                 Hashtable factories;
255                 static object removedMark = new object ();
256                 static object emptyMark = new object ();
257 #if (XML_DEP)
258                 Hashtable pending;
259                 string fileName;
260                 static object groupMark = new object ();
261 #endif
262                 Hashtable cache;
263
264                 Hashtable FileCache {
265                         get {
266                                 if (cache != null)
267                                         return cache;
268
269                                 cache = new Hashtable ();
270                                 return cache;
271                         }
272                 }
273
274                 public ConfigurationData () : this (null)
275                 {
276                 }
277
278                 public ConfigurationData (ConfigurationData parent)
279                 {
280                         this.parent = (parent == this) ? null : parent;
281                         factories = new Hashtable ();
282                 }
283
284                 // SECURITY-FIXME: limit this with an imperative assert for reading the specific file
285                 [FileIOPermission (SecurityAction.Assert, Unrestricted = true)]
286                 public bool Load (string fileName)
287                 {
288 #if (XML_DEP)
289                         this.fileName = fileName;
290                         if (fileName == null
291 #if !TARGET_JVM
292                                 || !File.Exists (fileName)
293 #endif
294 )
295                                 return false;
296                         
297                         XmlTextReader reader = null;
298
299                         try {
300 #if !TARGET_JVM
301                                 FileStream fs = new FileStream (fileName, FileMode.Open, FileAccess.Read);
302 #else
303                                 Stream fs = (Stream) vmw.common.IOUtils.getStream (fileName);
304
305                                 //patch for machine.config
306                                 if (fs == null && fileName.EndsWith ("machine.config")) {
307                                         fs = (Stream) IOUtils.getStreamForGHConfigs (fileName);
308                                 }
309
310                                 if (fs == null) {
311                                         return false;
312                                 }
313 #endif
314                                 reader = new XmlTextReader (fs);
315                                 if (InitRead (reader))
316                                         ReadConfigFile (reader);
317                         } catch (ConfigurationException) {
318                                 throw;
319                         } catch (Exception e) {
320                                 throw new ConfigurationException ("Error reading " + fileName, e);
321                         } finally {
322                                 if (reader != null)
323                                         reader.Close();
324                         }
325 #endif
326                         return true;
327                 }
328                 
329                 public bool LoadString (string data)
330                 {
331                         if (data == null)
332                                 return false;
333 #if (XML_DEP)
334                         XmlTextReader reader = null;
335
336                         try {
337                                 TextReader tr = new StringReader (data);
338                                 reader = new XmlTextReader (tr);
339                                 if (InitRead (reader))
340                                         ReadConfigFile (reader);
341                         } catch (ConfigurationException) {
342                                 throw;
343                         } catch (Exception e) {
344                                 throw new ConfigurationException ("Error reading " + fileName, e);
345                         } finally {
346                                 if (reader != null)
347                                         reader.Close();
348                         }
349 #endif
350                         return true;
351                 }
352                 
353                 object GetHandler (string sectionName)
354                 {
355                         lock (factories) {
356                                 object o = factories [sectionName];
357                                 if (o == null || o == removedMark) {
358                                         if (parent != null)
359                                                 return parent.GetHandler (sectionName);
360
361                                         return null;
362                                 }
363
364                                 if (o is IConfigurationSectionHandler)
365                                         return (IConfigurationSectionHandler) o;
366
367                                 o = CreateNewHandler (sectionName, (SectionData) o);
368                                 factories [sectionName] = o;
369                                 return o;
370                         }
371                 }
372
373                 object CreateNewHandler (string sectionName, SectionData section)
374                 {
375                         Type t = Type.GetType (section.TypeName);
376                         if (t == null)
377                                 throw new ConfigurationException ("Cannot get Type for " + section.TypeName);
378
379 #if false
380                         Type iconfig = typeof (IConfigurationSectionHandler);
381                         if (!iconfig.IsAssignableFrom (t))
382                                 throw new ConfigurationException (sectionName + " does not implement " + iconfig);
383 #endif
384                         
385                         object o = Activator.CreateInstance (t, true);
386                         if (o == null)
387                                 throw new ConfigurationException ("Cannot get instance for " + t);
388
389                         return o;
390                 }
391 #if (XML_DEP)
392                 XmlDocument GetInnerDoc (XmlDocument doc, int i, string [] sectionPath)
393                 {
394                         if (++i >= sectionPath.Length)
395                                 return doc;
396
397                         if (doc.DocumentElement == null)
398                                 return null;
399
400                         XmlNode node = doc.DocumentElement.FirstChild;
401                         while (node != null) {
402                                 if (node.Name == sectionPath [i]) {
403                                         ConfigXmlDocument result = new ConfigXmlDocument ();
404                                         result.Load (new StringReader (node.OuterXml));
405                                         return GetInnerDoc (result, i, sectionPath);
406                                 }
407                                 node = node.NextSibling;
408                         }
409
410                         return null;
411                 }
412
413                 XmlDocument GetDocumentForSection (string sectionName)
414                 {
415                         ConfigXmlDocument doc = new ConfigXmlDocument ();
416                         if (pending == null)
417                                 return doc;
418
419                         string [] sectionPath = sectionName.Split ('/');
420                         string outerxml = pending [sectionPath [0]] as string;
421                         if (outerxml == null)
422                                 return doc;
423
424                         StringReader reader = new StringReader (outerxml);
425                         XmlTextReader rd = new XmlTextReader (reader);
426                         rd.MoveToContent ();
427                         doc.LoadSingleElement (fileName, rd);
428
429                         return GetInnerDoc (doc, 0, sectionPath);
430                 }
431                 
432                 object GetConfigInternal (string sectionName)
433                 {
434                         object handler = GetHandler (sectionName);
435                         IConfigurationSectionHandler iconf = handler as IConfigurationSectionHandler;
436                         if (iconf == null)
437                                 return handler;
438
439                         object parentConfig = null;
440                         if (parent != null)
441                                 parentConfig = parent.GetConfig (sectionName);
442
443                         XmlDocument doc = GetDocumentForSection (sectionName);
444                         if (doc == null || doc.DocumentElement == null)
445                                 return parentConfig;
446                         
447                         return iconf.Create (parentConfig, fileName, doc.DocumentElement);
448                 }
449 #else
450                 object GetConfigInternal (string sectionName)
451                 {
452                     return null;
453                 }
454 #endif
455                 public object GetConfig (string sectionName)
456                 {
457                         object config;
458                         lock (this) {
459                                 config = this.FileCache [sectionName];
460                         }
461
462                         if (config == emptyMark)
463                                 return null;
464
465                         if (config != null)
466                                 return config;
467
468                         lock (this) {
469                                 config = GetConfigInternal (sectionName);
470                                 this.FileCache [sectionName] = (config == null) ? emptyMark : config;
471                         }
472
473                         return config;
474                 }
475
476                 private object LookForFactory (string key)
477                 {
478                         object o = factories [key];
479                         if (o != null)
480                                 return o;
481
482                         if (parent != null)
483                                 return parent.LookForFactory (key);
484
485                         return null;
486                 }
487 #if (XML_DEP)
488                 private bool InitRead (XmlTextReader reader)
489                 {
490                         reader.MoveToContent ();
491                         if (reader.NodeType != XmlNodeType.Element || reader.Name != "configuration")
492                                 ThrowException ("Configuration file does not have a valid root element", reader);
493
494                         if (reader.HasAttributes)
495                                 ThrowException ("Unrecognized attribute in root element", reader);
496                         if (reader.IsEmptyElement) {
497                                 reader.Skip ();
498                                 return false;
499                         }
500                         reader.Read ();
501                         reader.MoveToContent ();
502                         return reader.NodeType != XmlNodeType.EndElement;
503                 }
504
505                 // FIXME: this approach is not always safe and likely to cause bugs.
506                 private void MoveToNextElement (XmlTextReader reader)
507                 {
508                         while (reader.Read ()) {
509                                 XmlNodeType ntype = reader.NodeType;
510                                 if (ntype == XmlNodeType.Element)
511                                         return;
512
513                                 if (ntype != XmlNodeType.Whitespace &&
514                                     ntype != XmlNodeType.Comment &&
515                                     ntype != XmlNodeType.SignificantWhitespace &&
516                                     ntype != XmlNodeType.EndElement)
517                                         ThrowException ("Unrecognized element", reader);
518                         }
519                 }
520
521                 private void ReadSection (XmlTextReader reader, string sectionName)
522                 {
523                         string attName;
524                         string nameValue = null;
525                         string typeValue = null;
526                         string allowLoc = null, allowDef = null;
527                         bool requirePermission = false;
528                         string requirePer = null;
529                         bool allowLocation = true;
530                         AllowDefinition allowDefinition = AllowDefinition.Everywhere;
531
532                         while (reader.MoveToNextAttribute ()) {
533                                 attName = reader.Name;
534                                 if (attName == null)
535                                         continue;
536
537                                 if (attName == "allowLocation") {
538                                         if (allowLoc != null)
539                                                 ThrowException ("Duplicated allowLocation attribute.", reader);
540
541                                         allowLoc = reader.Value;
542                                         allowLocation = (allowLoc == "true");
543                                         if (!allowLocation && allowLoc != "false")
544                                                 ThrowException ("Invalid attribute value", reader);
545
546                                         continue;
547                                 }
548
549                                 if (attName == "requirePermission") {
550                                         if (requirePer != null)
551                                                 ThrowException ("Duplicated requirePermission attribute.", reader);
552                                         requirePer = reader.Value;
553                                         requirePermission = (requirePer == "true");
554                                         if (!requirePermission && requirePer != "false")
555                                                 ThrowException ("Invalid attribute value", reader);
556                                         continue;
557                                 }
558
559                                 if (attName == "allowDefinition") {
560                                         if (allowDef != null)
561                                                 ThrowException ("Duplicated allowDefinition attribute.", reader);
562
563                                         allowDef = reader.Value;
564                                         try {
565                                                 allowDefinition = (AllowDefinition) Enum.Parse (
566                                                                    typeof (AllowDefinition), allowDef);
567                                         } catch {
568                                                 ThrowException ("Invalid attribute value", reader);
569                                         }
570
571                                         continue;
572                                 }
573
574                                 if (attName == "type")  {
575                                         if (typeValue != null)
576                                                 ThrowException ("Duplicated type attribute.", reader);
577                                         typeValue = reader.Value;
578                                         continue;
579                                 }
580                                 
581                                 if (attName == "name")  {
582                                         if (nameValue != null)
583                                                 ThrowException ("Duplicated name attribute.", reader);
584                                         nameValue = reader.Value;
585                                         if (nameValue == "location")
586                                                 ThrowException ("location is a reserved section name", reader);
587                                         continue;
588                                 }
589
590                                 ThrowException ("Unrecognized attribute.", reader);
591                         }
592
593                         if (nameValue == null || typeValue == null)
594                                 ThrowException ("Required attribute missing", reader);
595
596                         if (sectionName != null)
597                                 nameValue = sectionName + '/' + nameValue;
598
599                         reader.MoveToElement();
600                         object o = LookForFactory (nameValue);
601                         if (o != null && o != removedMark)
602                                 ThrowException ("Already have a factory for " + nameValue, reader);
603                         SectionData section = new SectionData (nameValue, typeValue, allowLocation,
604                                 allowDefinition, requirePermission);
605                         section.FileName = fileName;
606                         factories [nameValue] = section;
607
608                         if (reader.IsEmptyElement)
609                                 reader.Skip ();
610                         else {
611                                 reader.Read ();
612                                 reader.MoveToContent ();
613                                 if (reader.NodeType != XmlNodeType.EndElement)
614                                         // sub-section inside a section
615                                         ReadSections (reader, nameValue);
616                                 reader.ReadEndElement ();
617                         }
618                         reader.MoveToContent ();
619                 }
620
621                 private void ReadRemoveSection (XmlTextReader reader, string sectionName)
622                 {
623                         if (!reader.MoveToNextAttribute () || reader.Name != "name")
624                                 ThrowException ("Unrecognized attribute.", reader);
625
626                         string removeValue = reader.Value;
627                         if (removeValue == null || removeValue.Length == 0)
628                                 ThrowException ("Empty name to remove", reader);
629
630                         reader.MoveToElement ();
631
632                         if (sectionName != null)
633                                 removeValue = sectionName + '/' + removeValue;
634
635                         object o = LookForFactory (removeValue);
636                         if (o != null && o == removedMark)
637                                 ThrowException ("No factory for " + removeValue, reader);
638
639                         factories [removeValue] = removedMark;
640                         MoveToNextElement (reader);
641                 }
642
643                 private void ReadSectionGroup (XmlTextReader reader, string configSection)
644                 {
645                         if (!reader.MoveToNextAttribute ())
646                                 ThrowException ("sectionGroup must have a 'name' attribute.", reader);
647
648                         string value = null;
649                         do {
650                                 if (reader.Name == "name") {
651                                         if (value != null)
652                                                 ThrowException ("Duplicate 'name' attribute.", reader);
653                                         value = reader.Value;
654                                 }
655                                 else
656 #if NET_2_0
657                                 if (reader.Name != "type")
658 #endif
659                                         ThrowException ("Unrecognized attribute.", reader);
660                         } while (reader.MoveToNextAttribute ());
661
662                         if (value == null)
663                                 ThrowException ("No 'name' attribute.", reader);
664                         
665                         if (value == "location")
666                                 ThrowException ("location is a reserved section name", reader);
667
668                         if (configSection != null)
669                                 value = configSection + '/' + value;
670
671                         object o = LookForFactory (value);
672                         if (o != null && o != removedMark && o != groupMark)
673                                 ThrowException ("Already have a factory for " + value, reader);
674
675                         factories [value] = groupMark;
676
677                         if (reader.IsEmptyElement) {
678                                 reader.Skip ();
679                                 reader.MoveToContent ();
680                         } else {
681                                 reader.Read ();
682                                 reader.MoveToContent ();
683                                 if (reader.NodeType != XmlNodeType.EndElement)
684                                         ReadSections (reader, value);
685                                 reader.ReadEndElement ();
686                                 reader.MoveToContent ();
687                         }
688                 }
689
690                 // It stops XmlReader consumption at where it found
691                 // surrounding EndElement i.e. EndElement is not consumed here
692                 private void ReadSections (XmlTextReader reader, string configSection)
693                 {
694                         int depth = reader.Depth;
695                         for (reader.MoveToContent ();
696                              reader.Depth == depth;
697                              reader.MoveToContent ()) {
698                                 string name = reader.Name;
699                                 if (name == "section") {
700                                         ReadSection (reader, configSection);
701                                         continue;
702                                 } 
703                                 
704                                 if (name == "remove") {
705                                         ReadRemoveSection (reader, configSection);
706                                         continue;
707                                 }
708
709                                 if (name == "clear") {
710                                         if (reader.HasAttributes)
711                                                 ThrowException ("Unrecognized attribute.", reader);
712
713                                         factories.Clear ();
714                                         MoveToNextElement (reader);
715                                         continue;
716                                 }
717
718                                 if (name == "sectionGroup") {
719                                         ReadSectionGroup (reader, configSection);
720                                         continue;
721                                 }
722                                 
723
724                                 ThrowException ("Unrecognized element: " + reader.Name, reader);
725                         }
726                 }
727
728                 void StorePending (string name, XmlTextReader reader)
729                 {
730                         if (pending == null)
731                                 pending = new Hashtable ();
732
733                         pending [name] = reader.ReadOuterXml ();
734                 }
735
736                 private void ReadConfigFile (XmlTextReader reader)
737                 {
738                         int depth = reader.Depth;
739                         for (reader.MoveToContent ();
740                              !reader.EOF && reader.NodeType != XmlNodeType.EndElement;
741                              reader.MoveToContent ()) {
742                                 string name = reader.Name;
743                                 if (name == "configSections") {
744                                         if (reader.HasAttributes)
745                                                 ThrowException ("Unrecognized attribute in <configSections>.", reader);
746                                         if (reader.IsEmptyElement)
747                                                 reader.Skip ();
748                                         else {
749                                                 reader.Read ();
750                                                 reader.MoveToContent ();
751                                                 if (reader.NodeType != XmlNodeType.EndElement)
752                                                         ReadSections (reader, null);
753                                                 reader.ReadEndElement ();
754                                         }
755                                 } else if (name != null && name != "") {
756                                         StorePending (name, reader);
757                                         MoveToNextElement (reader);
758                                 } else {
759                                         MoveToNextElement (reader);
760                                 }
761                         }
762                 }
763                 
764                 private void ThrowException (string text, XmlTextReader reader)
765                 {
766                         throw new ConfigurationException (text, fileName, reader.LineNumber);
767                 }
768 #endif
769         }
770 }
771
772