2 // System.Configuration.ConfigurationErrorsException.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Chris Toshok (toshok@ximian.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Configuration.Internal;
36 using System.Globalization;
37 using System.Runtime.Serialization;
38 using System.Collections;
41 namespace System.Configuration
43 /* disable the obsolete warnings about ConfigurationException */
44 #pragma warning disable 618
47 public class ConfigurationErrorsException : ConfigurationException
52 public ConfigurationErrorsException ()
56 public ConfigurationErrorsException (string message)
61 protected ConfigurationErrorsException (SerializationInfo info, StreamingContext context)
62 : base (info, context)
64 filename = info.GetString ("ConfigurationErrors_Filename");
65 line = info.GetInt32 ("ConfigurationErrors_Line");
68 public ConfigurationErrorsException (string message, Exception inner)
69 : base (message, inner)
73 public ConfigurationErrorsException (string message, XmlNode node)
74 : this (message, null, GetFilename (node), GetLineNumber (node))
78 public ConfigurationErrorsException (string message, Exception inner, XmlNode node)
79 : this (message, inner, GetFilename (node), GetLineNumber (node))
83 public ConfigurationErrorsException (string message, XmlReader reader)
84 : this (message, null, GetFilename (reader), GetLineNumber (reader))
88 public ConfigurationErrorsException (string message, Exception inner, XmlReader reader)
89 : this (message, inner, GetFilename (reader), GetLineNumber (reader))
93 public ConfigurationErrorsException (string message, string filename, int line)
94 : this (message, null, filename, line)
98 public ConfigurationErrorsException (string message, Exception inner, string filename, int line)
99 : base (message, inner)
101 this.filename = filename;
108 public override string BareMessage {
109 get { return base.BareMessage; }
112 public ICollection Errors {
113 get { throw new NotImplementedException (); }
116 public override string Filename {
117 get { return filename; }
120 public override int Line {
124 public override string Message {
127 if (!String.IsNullOrEmpty (filename)) {
129 msg = BareMessage + " (" + filename + " line " + line + ")";
131 msg = BareMessage + " (" + filename + ")";
134 msg = BareMessage + " (line " + line + ")";
144 public static string GetFilename (XmlReader reader)
146 // FIXME: eliminate this silly compatibility.
147 if (reader is IConfigErrorInfo)
148 return ((IConfigErrorInfo) reader).Filename;
150 return reader != null ? reader.BaseURI : null;
153 public static int GetLineNumber (XmlReader reader)
155 // FIXME: eliminate this silly compatibility.
156 if (reader is IConfigErrorInfo)
157 return ((IConfigErrorInfo) reader).LineNumber;
159 IXmlLineInfo li = reader as IXmlLineInfo;
160 return li != null ? li.LineNumber : 0;
163 public static string GetFilename (XmlNode node)
165 if (!(node is IConfigErrorInfo))
168 return ((IConfigErrorInfo) node).Filename;
171 public static int GetLineNumber (XmlNode node)
173 if (!(node is IConfigErrorInfo))
176 return ((IConfigErrorInfo) node).LineNumber;
179 public override void GetObjectData (SerializationInfo info, StreamingContext context)
181 base.GetObjectData (info, context);
182 info.AddValue ("ConfigurationErrors_Filename", filename);
183 info.AddValue ("ConfigurationErrors_Line", line);
186 readonly string filename;
189 #pragma warning restore