1 //------------------------------------------------------------------------------
2 // <copyright file="XmlSchemaException.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 namespace System
.Xml
.Schema
{
12 using System
.Resources
;
13 using System
.Runtime
.Serialization
;
14 using System
.Globalization
;
15 using System
.Diagnostics
;
16 using System
.Security
.Permissions
;
18 /// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException"]/*' />
20 public class XmlSchemaException
: SystemException
{
28 XmlSchemaObject sourceSchemaObject
;
30 // message != null for V1 exceptions deserialized in Whidbey
31 // message == null for V2 or higher exceptions; the exception message is stored on the base class (Exception._message)
34 /// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException.XmlSchemaException5"]/*' />
35 protected XmlSchemaException(SerializationInfo info
, StreamingContext context
) : base(info
, context
) {
36 res
= (string) info
.GetValue("res" , typeof(string));
37 args
= (string[]) info
.GetValue("args", typeof(string[]));
38 sourceUri
= (string) info
.GetValue("sourceUri", typeof(string));
39 lineNumber
= (int) info
.GetValue("lineNumber", typeof(int));
40 linePosition
= (int) info
.GetValue("linePosition", typeof(int));
42 // deserialize optional members
43 string version
= null;
44 foreach ( SerializationEntry e
in info
) {
45 if ( e
.Name
== "version" ) {
46 version
= (string)e
.Value
;
50 if ( version
== null ) {
51 // deserializing V1 exception
52 message
= CreateMessage( res
, args
);
55 // deserializing V2 or higher exception -> exception message is serialized by the base class (Exception._message)
61 /// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException.GetObjectData"]/*' />
62 [SecurityPermissionAttribute(SecurityAction
.LinkDemand
,SerializationFormatter
=true)]
63 public override void GetObjectData(SerializationInfo info
, StreamingContext context
) {
64 base.GetObjectData(info
, context
);
65 info
.AddValue("res", res
);
66 info
.AddValue("args", args
);
67 info
.AddValue("sourceUri", sourceUri
);
68 info
.AddValue("lineNumber", lineNumber
);
69 info
.AddValue("linePosition", linePosition
);
70 info
.AddValue("version", "2.0");
74 /// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException.XmlSchemaException1"]/*' />
75 public XmlSchemaException() : this(null) {
78 /// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException.XmlSchemaException2"]/*' />
79 public XmlSchemaException(String message
) : this (message
, ((Exception
)null), 0, 0) {
81 Debug
.Assert(message
== null || !message
.StartsWith("Sch_", StringComparison
.Ordinal
), "Do not pass a resource here!");
85 /// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException.XmlSchemaException0"]/*' />
86 public XmlSchemaException(String message
, Exception innerException
) : this (message
, innerException
, 0, 0) {
89 /// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException.XmlSchemaException3"]/*' />
90 public XmlSchemaException(String message
, Exception innerException
, int lineNumber
, int linePosition
) :
91 this((message
== null ? Res
.Sch_DefaultException
: Res
.Xml_UserException
), new string[] { message }
, innerException
, null, lineNumber
, linePosition
, null ) {
94 internal XmlSchemaException(string res
, string[] args
) :
95 this(res
, args
, null, null, 0, 0, null) {}
97 internal XmlSchemaException(string res
, string arg
) :
98 this(res
, new string[] { arg }
, null, null, 0, 0, null) {}
100 internal XmlSchemaException(string res
, string arg
, string sourceUri
, int lineNumber
, int linePosition
) :
101 this(res
, new string[] { arg }
, null, sourceUri
, lineNumber
, linePosition
, null) {}
103 internal XmlSchemaException(string res
, string sourceUri
, int lineNumber
, int linePosition
) :
104 this(res
, (string[])null, null, sourceUri
, lineNumber
, linePosition
, null) {}
106 internal XmlSchemaException(string res
, string[] args
, string sourceUri
, int lineNumber
, int linePosition
) :
107 this(res
, args
, null, sourceUri
, lineNumber
, linePosition
, null) {}
109 internal XmlSchemaException(string res
, XmlSchemaObject source
) :
110 this(res
, (string[])null, source
) {}
112 internal XmlSchemaException(string res
, string arg
, XmlSchemaObject source
) :
113 this(res
, new string[] { arg }
, source
) {}
115 internal XmlSchemaException(string res
, string[] args
, XmlSchemaObject source
) :
116 this(res
, args
, null, source
.SourceUri
, source
.LineNumber
, source
.LinePosition
, source
) {}
118 internal XmlSchemaException(string res
, string[] args
, Exception innerException
, string sourceUri
, int lineNumber
, int linePosition
, XmlSchemaObject source
) :
119 base (CreateMessage(res
, args
), innerException
) {
121 HResult
= HResults
.XmlSchema
;
124 this.sourceUri
= sourceUri
;
125 this.lineNumber
= lineNumber
;
126 this.linePosition
= linePosition
;
127 this.sourceSchemaObject
= source
;
130 internal static string CreateMessage(string res
, string[] args
) {
132 return Res
.GetString(res
, args
);
134 catch ( MissingManifestResourceException
) {
135 return "UNKNOWN("+res
+")";
139 internal string GetRes
{
145 internal string[] Args
{
150 /// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException.SourceUri"]/*' />
151 public string SourceUri
{
152 get { return this.sourceUri; }
155 /// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException.LineNumber"]/*' />
156 public int LineNumber
{
157 get { return this.lineNumber; }
160 /// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException.LinePosition"]/*' />
161 public int LinePosition
{
162 get { return this.linePosition; }
165 /// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException.SourceObject"]/*' />
166 public XmlSchemaObject SourceSchemaObject
{
167 get { return this.sourceSchemaObject; }
170 /*internal static XmlSchemaException Create(string res) { //Since internal overload with res string will clash with public constructor that takes in a message
171 return new XmlSchemaException(res, (string[])null, null, null, 0, 0, null);
174 internal void SetSource(string sourceUri
, int lineNumber
, int linePosition
) {
175 this.sourceUri
= sourceUri
;
176 this.lineNumber
= lineNumber
;
177 this.linePosition
= linePosition
;
180 internal void SetSchemaObject(XmlSchemaObject source
) {
181 this.sourceSchemaObject
= source
;
184 internal void SetSource(XmlSchemaObject source
) {
185 this.sourceSchemaObject
= source
;
186 this.sourceUri
= source
.SourceUri
;
187 this.lineNumber
= source
.LineNumber
;
188 this.linePosition
= source
.LinePosition
;
191 internal void SetResourceId(string resourceId
) {
192 this.res
= resourceId
;
195 public override string Message
{
197 return (message
== null) ? base.Message
: message
;
201 } // namespace System.Xml.Schema