2 // System.Web.Compilation.CompilationException
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Collections
;
33 using System
.Collections
.Specialized
;
34 using System
.CodeDom
.Compiler
;
35 using System
.Runtime
.Serialization
;
36 using System
.Security
.Permissions
;
40 namespace System
.Web
.Compilation
43 internal class CompilationException
: HtmlizedException
46 CompilerErrorCollection errors
;
47 CompilerResults results
;
52 CompilationException (SerializationInfo info
, StreamingContext context
)
53 : base (info
, context
)
55 filename
= info
.GetString ("filename");
56 errors
= info
.GetValue ("errors", typeof (CompilerErrorCollection
)) as CompilerErrorCollection
;
57 results
= info
.GetValue ("results", typeof (CompilerResults
)) as CompilerResults
;
58 fileText
= info
.GetString ("fileText");
59 errmsg
= info
.GetString ("errmsg");
60 errorLines
= info
.GetValue ("errorLines", typeof (int[])) as int[];
63 public CompilationException (string filename
, CompilerErrorCollection errors
, string fileText
)
65 this.filename
= filename
;
67 this.fileText
= fileText
;
70 public CompilationException (string filename
, CompilerResults results
, string fileText
)
71 : this (filename
, results
!= null ? results
.Errors
: null, fileText
)
73 this.results
= results
;
76 [SecurityPermission (SecurityAction
.Demand
, SerializationFormatter
= true)]
77 public override void GetObjectData (SerializationInfo info
, StreamingContext ctx
)
79 base.GetObjectData (info
, ctx
);
80 info
.AddValue ("filename", filename
);
81 info
.AddValue ("errors", errors
);
82 info
.AddValue ("results", results
);
83 info
.AddValue ("fileText", fileText
);
84 info
.AddValue ("errmsg", errmsg
);
85 info
.AddValue ("errorLines", errorLines
);
88 public override string Message
{
89 get { return ErrorMessage; }
92 public override string SourceFile
{
94 if (errors
== null || errors
.Count
== 0)
97 return errors
[0].FileName
;
101 public override string FileName
{
102 get { return filename; }
105 public override string Title
{
106 get { return "Compilation Error"; }
109 public override string Description
{
111 return "Error compiling a resource required to service this request. " +
112 "Review your source file and modify it to fix this error.";
116 public override string ErrorMessage
{
118 if (errmsg
== null && errors
!= null) {
119 CompilerError firstError
= null;
121 foreach (CompilerError err
in errors
) {
128 errmsg
= firstError
.ToString ();
129 int idx
= errmsg
.IndexOf (" : error ");
131 errmsg
= errmsg
.Substring (idx
+ 9);
138 public override string FileText
{
139 get { return fileText; }
142 public override int [] ErrorLines
{
144 if (errorLines
== null && errors
!= null) {
145 ArrayList list
= new ArrayList ();
146 foreach (CompilerError err
in errors
) {
150 if (err
.Line
!= 0 && !list
.Contains (err
.Line
))
153 errorLines
= (int []) list
.ToArray (typeof (int));
154 Array
.Sort (errorLines
);
161 public override bool ErrorLinesPaired
{
162 get { return false; }
165 public StringCollection CompilerOutput
{
170 return results
.Output
;
174 public CompilerResults Results
{
175 get { return results; }