mscorlib(4.0.0.0) API with additions
XmlException.cs
2 using System.Resources;
5 using System.Threading;
6 
7 namespace System.Xml
8 {
10  [Serializable]
11  [global::__DynamicallyInvokable]
13  {
14  private string res;
15 
16  private string[] args;
17 
18  private int lineNumber;
19 
20  private int linePosition;
21 
22  [OptionalField]
23  private string sourceUri;
24 
25  private string message;
26 
29  [global::__DynamicallyInvokable]
30  public int LineNumber
31  {
32  [global::__DynamicallyInvokable]
33  get
34  {
35  return lineNumber;
36  }
37  }
38 
41  [global::__DynamicallyInvokable]
42  public int LinePosition
43  {
44  [global::__DynamicallyInvokable]
45  get
46  {
47  return linePosition;
48  }
49  }
50 
53  public string SourceUri => sourceUri;
54 
57  [global::__DynamicallyInvokable]
58  public override string Message
59  {
60  [global::__DynamicallyInvokable]
61  get
62  {
63  if (message != null)
64  {
65  return message;
66  }
67  return base.Message;
68  }
69  }
70 
71  internal string ResString => res;
72 
77  : base(info, context)
78  {
79  res = (string)info.GetValue("res", typeof(string));
80  args = (string[])info.GetValue("args", typeof(string[]));
81  lineNumber = (int)info.GetValue("lineNumber", typeof(int));
82  linePosition = (int)info.GetValue("linePosition", typeof(int));
83  sourceUri = string.Empty;
84  string text = null;
85  SerializationInfoEnumerator enumerator = info.GetEnumerator();
86  while (enumerator.MoveNext())
87  {
88  SerializationEntry current = enumerator.Current;
89  string name = current.Name;
90  if (!(name == "sourceUri"))
91  {
92  if (name == "version")
93  {
94  text = (string)current.Value;
95  }
96  }
97  else
98  {
99  sourceUri = (string)current.Value;
100  }
101  }
102  if (text == null)
103  {
104  message = CreateMessage(res, args, lineNumber, linePosition);
105  }
106  else
107  {
108  message = null;
109  }
110  }
111 
115  [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter = true)]
116  public override void GetObjectData(SerializationInfo info, StreamingContext context)
117  {
118  base.GetObjectData(info, context);
119  info.AddValue("res", res);
120  info.AddValue("args", args);
121  info.AddValue("lineNumber", lineNumber);
122  info.AddValue("linePosition", linePosition);
123  info.AddValue("sourceUri", sourceUri);
124  info.AddValue("version", "2.0");
125  }
126 
128  [global::__DynamicallyInvokable]
129  public XmlException()
130  : this(null)
131  {
132  }
133 
136  [global::__DynamicallyInvokable]
137  public XmlException(string message)
138  : this(message, (Exception)null, 0, 0)
139  {
140  }
141 
145  [global::__DynamicallyInvokable]
146  public XmlException(string message, Exception innerException)
147  : this(message, innerException, 0, 0)
148  {
149  }
150 
156  [global::__DynamicallyInvokable]
157  public XmlException(string message, Exception innerException, int lineNumber, int linePosition)
158  : this(message, innerException, lineNumber, linePosition, null)
159  {
160  }
161 
162  internal XmlException(string message, Exception innerException, int lineNumber, int linePosition, string sourceUri)
163  : base(FormatUserMessage(message, lineNumber, linePosition), innerException)
164  {
165  base.HResult = -2146232000;
166  res = ((message == null) ? "Xml_DefaultException" : "Xml_UserException");
167  args = new string[1]
168  {
169  message
170  };
171  this.sourceUri = sourceUri;
172  this.lineNumber = lineNumber;
173  this.linePosition = linePosition;
174  }
175 
176  internal XmlException(string res, string[] args)
177  : this(res, args, null, 0, 0, null)
178  {
179  }
180 
181  internal XmlException(string res, string[] args, string sourceUri)
182  : this(res, args, null, 0, 0, sourceUri)
183  {
184  }
185 
186  internal XmlException(string res, string arg)
187  : this(res, new string[1]
188  {
189  arg
190  }, null, 0, 0, null)
191  {
192  }
193 
194  internal XmlException(string res, string arg, string sourceUri)
195  : this(res, new string[1]
196  {
197  arg
198  }, null, 0, 0, sourceUri)
199  {
200  }
201 
202  internal XmlException(string res, string arg, IXmlLineInfo lineInfo)
203  : this(res, new string[1]
204  {
205  arg
206  }, lineInfo, null)
207  {
208  }
209 
210  internal XmlException(string res, string arg, Exception innerException, IXmlLineInfo lineInfo)
211  : this(res, new string[1]
212  {
213  arg
214  }, innerException, lineInfo?.LineNumber ?? 0, lineInfo?.LinePosition ?? 0, null)
215  {
216  }
217 
218  internal XmlException(string res, string arg, IXmlLineInfo lineInfo, string sourceUri)
219  : this(res, new string[1]
220  {
221  arg
222  }, lineInfo, sourceUri)
223  {
224  }
225 
226  internal XmlException(string res, string[] args, IXmlLineInfo lineInfo)
227  : this(res, args, lineInfo, null)
228  {
229  }
230 
231  internal XmlException(string res, string[] args, IXmlLineInfo lineInfo, string sourceUri)
232  : this(res, args, null, lineInfo?.LineNumber ?? 0, lineInfo?.LinePosition ?? 0, sourceUri)
233  {
234  }
235 
236  internal XmlException(string res, int lineNumber, int linePosition)
237  : this(res, null, null, lineNumber, linePosition)
238  {
239  }
240 
241  internal XmlException(string res, string arg, int lineNumber, int linePosition)
242  : this(res, new string[1]
243  {
244  arg
245  }, null, lineNumber, linePosition, null)
246  {
247  }
248 
249  internal XmlException(string res, string arg, int lineNumber, int linePosition, string sourceUri)
250  : this(res, new string[1]
251  {
252  arg
253  }, null, lineNumber, linePosition, sourceUri)
254  {
255  }
256 
257  internal XmlException(string res, string[] args, int lineNumber, int linePosition)
258  : this(res, args, null, lineNumber, linePosition, null)
259  {
260  }
261 
262  internal XmlException(string res, string[] args, int lineNumber, int linePosition, string sourceUri)
263  : this(res, args, null, lineNumber, linePosition, sourceUri)
264  {
265  }
266 
267  internal XmlException(string res, string[] args, Exception innerException, int lineNumber, int linePosition)
268  : this(res, args, innerException, lineNumber, linePosition, null)
269  {
270  }
271 
272  internal XmlException(string res, string[] args, Exception innerException, int lineNumber, int linePosition, string sourceUri)
273  : base(CreateMessage(res, args, lineNumber, linePosition), innerException)
274  {
275  base.HResult = -2146232000;
276  this.res = res;
277  this.args = args;
278  this.sourceUri = sourceUri;
279  this.lineNumber = lineNumber;
280  this.linePosition = linePosition;
281  }
282 
283  private static string FormatUserMessage(string message, int lineNumber, int linePosition)
284  {
285  if (message == null)
286  {
287  return CreateMessage("Xml_DefaultException", null, lineNumber, linePosition);
288  }
289  if (lineNumber == 0 && linePosition == 0)
290  {
291  return message;
292  }
293  return CreateMessage("Xml_UserException", new string[1]
294  {
295  message
296  }, lineNumber, linePosition);
297  }
298 
299  private static string CreateMessage(string res, string[] args, int lineNumber, int linePosition)
300  {
301  try
302  {
303  if (lineNumber == 0)
304  {
305  return Res.GetString(res, args);
306  }
307  string text = lineNumber.ToString(CultureInfo.InvariantCulture);
308  string text2 = linePosition.ToString(CultureInfo.InvariantCulture);
309  string @string = Res.GetString(res, args);
310  return Res.GetString("Xml_MessageWithErrorPosition", @string, text, text2);
311  }
313  {
314  return "UNKNOWN(" + res + ")";
315  }
316  }
317 
318  internal static string[] BuildCharExceptionArgs(string data, int invCharIndex)
319  {
320  return BuildCharExceptionArgs(data[invCharIndex], (invCharIndex + 1 < data.Length) ? data[invCharIndex + 1] : '\0');
321  }
322 
323  internal static string[] BuildCharExceptionArgs(char[] data, int invCharIndex)
324  {
325  return BuildCharExceptionArgs(data, data.Length, invCharIndex);
326  }
327 
328  internal static string[] BuildCharExceptionArgs(char[] data, int length, int invCharIndex)
329  {
330  return BuildCharExceptionArgs(data[invCharIndex], (invCharIndex + 1 < length) ? data[invCharIndex + 1] : '\0');
331  }
332 
333  internal static string[] BuildCharExceptionArgs(char invChar, char nextChar)
334  {
335  string[] array = new string[2];
336  if (XmlCharType.IsHighSurrogate(invChar) && nextChar != 0)
337  {
338  int num = XmlCharType.CombineSurrogateChar(nextChar, invChar);
339  array[0] = new string(new char[2]
340  {
341  invChar,
342  nextChar
343  });
344  array[1] = string.Format(CultureInfo.InvariantCulture, "0x{0:X2}", new object[1]
345  {
346  num
347  });
348  }
349  else
350  {
351  if (invChar == '\0')
352  {
353  array[0] = ".";
354  }
355  else
356  {
357  array[0] = invChar.ToString(CultureInfo.InvariantCulture);
358  }
359  array[1] = string.Format(CultureInfo.InvariantCulture, "0x{0:X2}", new object[1]
360  {
361  (int)invChar
362  });
363  }
364  return array;
365  }
366 
367  internal static bool IsCatchableException(Exception e)
368  {
369  if (!(e is StackOverflowException) && !(e is OutOfMemoryException) && !(e is ThreadAbortException) && !(e is ThreadInterruptedException) && !(e is NullReferenceException))
370  {
371  return !(e is AccessViolationException);
372  }
373  return false;
374  }
375  }
376 }
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
Describes a set of security permissions applied to code. This class cannot be inherited.
int LineNumber
Gets the line number indicating where the error occurred.
Definition: XmlException.cs:31
Serves as the base class for system exceptions namespace.
int LinePosition
Gets the line position indicating where the error occurred.
Definition: XmlException.cs:43
Definition: __Canon.cs:3
Describes the source and destination of a given serialized stream, and provides an additional caller-...
string SourceUri
Gets the location of the XML file.
Definition: XmlException.cs:53
XmlException(string message, Exception innerException, int lineNumber, int linePosition)
Initializes a new instance of the XmlException class with the specified message, inner exception,...
SecurityAction
Specifies the security actions that can be performed using declarative security.
The exception that is thrown when a T:System.Threading.Thread is interrupted while it is in a waiting...
XmlException()
Initializes a new instance of the XmlException class.
XmlException(string message)
Initializes a new instance of the XmlException class with a specified error message.
override void GetObjectData(SerializationInfo info, StreamingContext context)
Streams all the XmlException properties into the T:System.Runtime.Serialization.SerializationInfo cla...
XmlException(string message, Exception innerException)
Initializes a new instance of the XmlException class.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
The exception that is thrown if the main assembly does not contain the resources for the neutral cult...
Returns detailed information about the last exception.
Definition: XmlException.cs:12
Exception()
Initializes a new instance of the T:System.Exception class.
Definition: Exception.cs:286
XmlException(SerializationInfo info, StreamingContext context)
Initializes a new instance of the XmlException class using the information in the T:System....
Definition: XmlException.cs:76
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
Specifies that the class can be serialized.
Holds the value, T:System.Type, and name of a serialized object.
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
The exception that is thrown when a call is made to the M:System.Threading.Thread....
Provides a formatter-friendly mechanism for parsing the data in T:System.Runtime.Serialization....
override string Message
Gets a message describing the current exception.
Definition: XmlException.cs:59
object Value
Gets the value contained in the object.
string Name
Gets the name of the object.
bool MoveNext()
Updates the enumerator to the next item.