File: ErrorFormatter.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (1974 lines) | stat: -rw-r--r-- 78,257 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
//------------------------------------------------------------------------------
// <copyright file="ErrorFormatter.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

/*********************************

Class hierarchy

ErrorFormatter (abstract)
    UnhandledErrorFormatter
        SecurityErrorFormatter
        UseLastUnhandledErrorFormatter
        TemplatedMailRuntimeErrorFormatter
    PageNotFoundErrorFormatter
    PageForbiddenErrorFormatter
    GenericApplicationErrorFormatter
    FormatterWithFileInfo (abstract)
        ParseErrorFormatter
        ConfigErrorFormatter
    DynamicCompileErrorFormatter
        TemplatedMailCompileErrorFormatter    
    UrlAuthFailedErrorFormatter
    TraceHandlerErrorFormatter
    TemplatedMailErrorFormatterGenerator
    AuthFailedErrorFormatter
    FileAccessFailedErrorFormatter
    PassportAuthFailedErrorFormatter

**********************************/

/*
 * Object used to put together ASP.NET HTML error messages
 *
 * Copyright (c) 1999 Microsoft Corporation
 */

namespace System.Web {
    using System.Runtime.Serialization.Formatters;
    using System.Text;
    using System.Diagnostics;
    using System.Drawing;
    using System.Reflection;
    using System.Configuration.Assemblies;
    using System.Runtime.InteropServices;
    using System.Runtime.Serialization;
    using System.IO;
    using System.Globalization;
    using System.Web.Hosting;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.Util;
    using System.Web.Compilation;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Text.RegularExpressions;
    using System.CodeDom.Compiler;
    using System.ComponentModel;
    using Debug=System.Web.Util.Debug;
    using System.Web.Management;
    using System.Configuration;
    using System.Security;
    using System.Security.Permissions;

    /*
     * This is an abstract base class from which we derive other formatters.
     */
    internal abstract class ErrorFormatter {

        private StringCollection _adaptiveMiscContent;
        private StringCollection _adaptiveStackTrace;
        protected bool           _dontShowVersion = false;

        private const string startExpandableBlock =
            "<br><div class=\"expandable\" onclick=\"OnToggleTOCLevel1('{0}')\">" +
            "{1}" +
            ":</div>\r\n" +
            "<div id=\"{0}\" style=\"display: none;\">\r\n" +
            "            <br><table width=100% bgcolor=\"#ffffcc\">\r\n" +
            "               <tr>\r\n" +
            "                  <td>\r\n" +
            "                      <code><pre>\r\n\r\n";

        private const string endExpandableBlock =
            "                      </pre></code>\r\n\r\n" +
            "                  </td>\r\n" +
            "               </tr>\r\n" +
            "            </table>\r\n\r\n" +
            "            \r\n\r\n" +
            "</div>\r\n";

        private const string toggleScript = @"
        <script type=""text/javascript"">
        function OnToggleTOCLevel1(level2ID)
        {
        var elemLevel2 = document.getElementById(level2ID);
        if (elemLevel2.style.display == 'none')
        {
            elemLevel2.style.display = '';
        }
        else {
            elemLevel2.style.display = 'none';
        }
        }
        </script>
                            ";

        protected const string BeginLeftToRightTag = "<div dir=\"ltr\">";
        protected const string EndLeftToRightTag = "</div>";

        internal static bool RequiresAdaptiveErrorReporting(HttpContext context)
        {

            // If HostingInit failed, don't try to continue, as we are not sufficiently
            // initialized to execute this code (VSWhidbey 210495)
            if (HttpRuntime.HostingInitFailed)
                return false;

            HttpRequest request = (context != null) ? context.Request : null;
            if (context != null && context.WorkerRequest is System.Web.SessionState.StateHttpWorkerRequest)
                return false;

            // Request.Browser might throw if the configuration file has some
            // bad format.
            HttpBrowserCapabilities browser = null;
            try {
                browser = (request != null) ? request.Browser : null;
            }
            catch {
                return false;
            }

            if (browser != null &&
                browser["requiresAdaptiveErrorReporting"] == "true") {
                return true;
            }
            return false;
        }

        private Literal CreateBreakLiteral() {
            Literal breakControl = new Literal();
            breakControl.Text = "<br/>";
            return breakControl;
        }

        private Label CreateLabelFromText(String text) {
            Label label = new Label();
            label.Text = text;
            return label;
        }

        // Return error message in markup using adaptive rendering of web
        // controls.  This would also set the corresponding headers of the
        // response accordingly so content can be shown properly on devices.
        // This method has been added with the same signature of
        // GetHtmlErrorMessage for consistency.
        internal virtual string GetAdaptiveErrorMessage(HttpContext context, bool dontShowSensitiveInfo) {

            // This call will compute and set all the necessary properties of
            // this instance of ErrorFormatter.  Then the controls below can
            // collect info from the properties.  The returned html is safely
            // ignored.
            GetHtmlErrorMessage(dontShowSensitiveInfo);

            // We need to inform the Response object that adaptive error is used
            // so it can adjust the status code right before headers are written out.
            // It is because some mobile devices/browsers can display a page
            // content only if it is a normal response instead of response that
            // has error status code.
            context.Response.UseAdaptiveError = true;

            try {
                Page page = new ErrorFormatterPage();
                page.EnableViewState = false;

                HtmlForm form = new HtmlForm();
                page.Controls.Add(form);
                IParserAccessor formAdd = (IParserAccessor) form;

                // Display a server error text with the application name
                Label label = CreateLabelFromText(SR.GetString(SR.Error_Formatter_ASPNET_Error, HttpRuntime.AppDomainAppVirtualPath));
                label.ForeColor = Color.Red;
                label.Font.Bold = true;
                label.Font.Size = FontUnit.Large;
                formAdd.AddParsedSubObject(label);
                formAdd.AddParsedSubObject(CreateBreakLiteral());

                // Title
                label = CreateLabelFromText(ErrorTitle);
                label.ForeColor = Color.Maroon;
                label.Font.Bold = true;
                label.Font.Italic = true;
                formAdd.AddParsedSubObject(label);
                formAdd.AddParsedSubObject(CreateBreakLiteral());

                // Description
                formAdd.AddParsedSubObject(CreateLabelFromText(SR.GetString(SR.Error_Formatter_Description) + " " + Description));
                formAdd.AddParsedSubObject(CreateBreakLiteral());

                // Misc Title
                String miscTitle = MiscSectionTitle;
                if (!String.IsNullOrEmpty(miscTitle)) {
                    formAdd.AddParsedSubObject(CreateLabelFromText(miscTitle));
                    formAdd.AddParsedSubObject(CreateBreakLiteral());
                }

                // Misc Info
                StringCollection miscContent = AdaptiveMiscContent;
                if (miscContent != null && miscContent.Count > 0) {
                    foreach (String contentLine in miscContent) {
                        formAdd.AddParsedSubObject(CreateLabelFromText(contentLine));
                        formAdd.AddParsedSubObject(CreateBreakLiteral());
                    }
                }

                // File & line# info
                String sourceFilePath = GetDisplayPath();
                if (!String.IsNullOrEmpty(sourceFilePath)) {
                    String text = SR.GetString(SR.Error_Formatter_Source_File) + " " + sourceFilePath;
                    formAdd.AddParsedSubObject(CreateLabelFromText(text));
                    formAdd.AddParsedSubObject(CreateBreakLiteral());

                    text = SR.GetString(SR.Error_Formatter_Line) + " " + SourceFileLineNumber;
                    formAdd.AddParsedSubObject(CreateLabelFromText(text));
                    formAdd.AddParsedSubObject(CreateBreakLiteral());
                }

                // Stack trace info
                StringCollection stackTrace = AdaptiveStackTrace;
                if (stackTrace != null && stackTrace.Count > 0) {
                    foreach (String stack in stackTrace) {
                        formAdd.AddParsedSubObject(CreateLabelFromText(stack));
                        formAdd.AddParsedSubObject(CreateBreakLiteral());
                    }
                }

                // Temporarily use a string writer to capture the output and
                // return it accordingly.
                StringWriter stringWriter = new StringWriter(CultureInfo.CurrentCulture);
                TextWriter textWriter = context.Response.SwitchWriter(stringWriter);
                page.ProcessRequest(context);
                context.Response.SwitchWriter(textWriter);

                return stringWriter.ToString();
            }
            catch {
                return GetStaticErrorMessage(context);
            }
        }

        private string GetPreferredRenderingType(HttpContext context) {
            HttpRequest request = (context != null) ? context.Request : null;

            // Request.Browser might throw if the configuration file has some
            // bad format.
            HttpBrowserCapabilities browser = null;
            try {
                browser = (request != null) ? request.Browser : null;
            }
            catch {
                return String.Empty;
            }
            return ((browser != null) ? browser["preferredRenderingType"] : String.Empty);
        }

        private string GetStaticErrorMessage(HttpContext context) {
            string preferredRenderingType = GetPreferredRenderingType(context);
            Debug.Assert(preferredRenderingType != null);

            string errorMessage;
            if (StringUtil.StringStartsWithIgnoreCase(preferredRenderingType, "xhtml")) {
                errorMessage = FormatStaticErrorMessage(StaticErrorFormatterHelper.XhtmlErrorBeginTemplate,
                                                        StaticErrorFormatterHelper.XhtmlErrorEndTemplate);
            }
            else if (StringUtil.StringStartsWithIgnoreCase(preferredRenderingType, "wml")) {
                errorMessage = FormatStaticErrorMessage(StaticErrorFormatterHelper.WmlErrorBeginTemplate,
                                                        StaticErrorFormatterHelper.WmlErrorEndTemplate);

                // VSWhidbey 161754: In the case that headers have been written,
                // we should try to set the content type only if needed.
                const string wmlContentType = "text/vnd.wap.wml";
                if (String.Compare(context.Response.ContentType, 0,
                                   wmlContentType, 0, wmlContentType.Length,
                                   StringComparison.OrdinalIgnoreCase) != 0) {
                    context.Response.ContentType = wmlContentType;
                }
            }
            else {
                errorMessage = FormatStaticErrorMessage(StaticErrorFormatterHelper.ChtmlErrorBeginTemplate,
                                                        StaticErrorFormatterHelper.ChtmlErrorEndTemplate);
            }
            return errorMessage;
        }

        private string FormatStaticErrorMessage(string errorBeginTemplate,
                                                string errorEndTemplate) {
            StringBuilder errorContent = new StringBuilder();

            // Server error text with the application name and Title
            string errorHeader = SR.GetString(SR.Error_Formatter_ASPNET_Error, HttpRuntime.AppDomainAppVirtualPath);
            errorContent.Append(String.Format(CultureInfo.CurrentCulture, errorBeginTemplate, errorHeader, ErrorTitle));

            // Description
            errorContent.Append(SR.GetString(SR.Error_Formatter_Description) + " " + Description);
            errorContent.Append(StaticErrorFormatterHelper.Break);

            // Misc Title
            String miscTitle = MiscSectionTitle;
            if (miscTitle != null && miscTitle.Length > 0) {
                errorContent.Append(miscTitle);
                errorContent.Append(StaticErrorFormatterHelper.Break);
            }

            // Misc Info
            StringCollection miscContent = AdaptiveMiscContent;
            if (miscContent != null && miscContent.Count > 0) {
                foreach (String contentLine in miscContent) {
                    errorContent.Append(contentLine);
                    errorContent.Append(StaticErrorFormatterHelper.Break);
                }
            }

            // File & line# info
            String sourceFilePath = GetDisplayPath();
            if (!String.IsNullOrEmpty(sourceFilePath)) {
                String text = SR.GetString(SR.Error_Formatter_Source_File) + " " + sourceFilePath;
                errorContent.Append(text);
                errorContent.Append(StaticErrorFormatterHelper.Break);

                text = SR.GetString(SR.Error_Formatter_Line) + " " + SourceFileLineNumber;
                errorContent.Append(text);
                errorContent.Append(StaticErrorFormatterHelper.Break);
            }

            // Stack trace info
            StringCollection stackTrace = AdaptiveStackTrace;
            if (stackTrace != null && stackTrace.Count > 0) {
                foreach (String stack in stackTrace) {
                    errorContent.Append(stack);
                    errorContent.Append(StaticErrorFormatterHelper.Break);
                }
            }

            errorContent.Append(errorEndTemplate);
            return errorContent.ToString();
        }

        internal string GetErrorMessage() {
            return GetErrorMessage(HttpContext.Current, true);
        }

        // Return error message by checking if adaptive error formatting
        // should be used.
        internal virtual string GetErrorMessage(HttpContext context, bool dontShowSensitiveInfo) {
            if (RequiresAdaptiveErrorReporting(context)) {
                return GetAdaptiveErrorMessage(context, dontShowSensitiveInfo);
            }
            return GetHtmlErrorMessage(dontShowSensitiveInfo);
        }

        internal /*public*/ string GetHtmlErrorMessage() {
            return GetHtmlErrorMessage(true);
        }

        internal /*public*/ string GetHtmlErrorMessage(bool dontShowSensitiveInfo) {

            // Give the formatter a chance to prepare its state
            PrepareFormatter();

            StringBuilder sb = new StringBuilder();

            // 


            sb.Append("<!DOCTYPE html>\r\n");
            sb.Append("<html");

            // VSWhidbey 477678: Honor right to left language text format.
            if (IsTextRightToLeft) {
                sb.Append(" dir=\"rtl\"");
            }

            sb.Append(">\r\n");
            sb.Append("    <head>\r\n");
            sb.Append("        <title>" + ErrorTitle + "</title>\r\n");
            sb.Append("        <meta name=\"viewport\" content=\"width=device-width\" />\r\n");
            sb.Append("        <style>\r\n");
            sb.Append("         body {font-family:\"Verdana\";font-weight:normal;font-size: .7em;color:black;} \r\n");
            sb.Append("         p {font-family:\"Verdana\";font-weight:normal;color:black;margin-top: -5px}\r\n");
            sb.Append("         b {font-family:\"Verdana\";font-weight:bold;color:black;margin-top: -5px}\r\n");
            sb.Append("         H1 { font-family:\"Verdana\";font-weight:normal;font-size:18pt;color:red }\r\n");
            sb.Append("         H2 { font-family:\"Verdana\";font-weight:normal;font-size:14pt;color:maroon }\r\n");
            sb.Append("         pre {font-family:\"Consolas\",\"Lucida Console\",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}\r\n");
            sb.Append("         .marker {font-weight: bold; color: black;text-decoration: none;}\r\n");
            sb.Append("         .version {color: gray;}\r\n");
            sb.Append("         .error {margin-bottom: 10px;}\r\n");
            sb.Append("         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }\r\n");
            sb.Append("         @media screen and (max-width: 639px) {\r\n");
            sb.Append("          pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }\r\n");
            sb.Append("         }\r\n");
            sb.Append("         @media screen and (max-width: 479px) {\r\n");
            sb.Append("          pre { width: 280px; }\r\n");
            sb.Append("         }\r\n");
            sb.Append("        </style>\r\n");
            sb.Append("    </head>\r\n\r\n");
            sb.Append("    <body bgcolor=\"white\">\r\n\r\n");
            sb.Append("            <span><H1>" + SR.GetString(SR.Error_Formatter_ASPNET_Error, HttpRuntime.AppDomainAppVirtualPath) + "<hr width=100% size=1 color=silver></H1>\r\n\r\n");
            sb.Append("            <h2> <i>" + ErrorTitle + "</i> </h2></span>\r\n\r\n");
            sb.Append("            <font face=\"Arial, Helvetica, Geneva, SunSans-Regular, sans-serif \">\r\n\r\n");
            sb.Append("            <b> " + SR.GetString(SR.Error_Formatter_Description) +  " </b>" + Description + "\r\n");
            sb.Append("            <br><br>\r\n\r\n");
            if (MiscSectionTitle != null) {
                sb.Append("            <b> " + MiscSectionTitle + ": </b>" + MiscSectionContent + "<br><br>\r\n\r\n");
            }

            WriteColoredSquare(sb, ColoredSquareTitle, ColoredSquareDescription, ColoredSquareContent, WrapColoredSquareContentLines);
            if (ShowSourceFileInfo) {
                string displayPath = GetDisplayPath();
                if (displayPath == null)
                    displayPath = SR.GetString(SR.Error_Formatter_No_Source_File);
                sb.Append("            <b> " + SR.GetString(SR.Error_Formatter_Source_File) + " </b> " + displayPath + "<b> &nbsp;&nbsp; " + SR.GetString(SR.Error_Formatter_Line) + " </b> " + SourceFileLineNumber + "\r\n");
                sb.Append("            <br><br>\r\n\r\n");
            }

            ConfigurationErrorsException configErrors = Exception as ConfigurationErrorsException;
            if (configErrors != null && configErrors.Errors.Count > 1) {
                sb.Append(String.Format(CultureInfo.InvariantCulture, startExpandableBlock, "additionalConfigurationErrors",
                    SR.GetString(SR.TmplConfigurationAdditionalError)));

                //
                // Get the configuration message as though there were user code on the stack,
                // so that the full path to the configuration file is not shown if the app
                // does not have PathDiscoveryPermission.
                // 
                bool revertPermitOnly = false;
                try {
                    PermissionSet ps = HttpRuntime.NamedPermissionSet;
                    if (ps != null) {
                        ps.PermitOnly();
                        revertPermitOnly = true;
                    }
                    
                    int errorNumber = 0;
                    foreach(ConfigurationException configurationError in configErrors.Errors) {
                        if (errorNumber > 0) {
                            sb.Append(configurationError.Message);
                            sb.Append("<BR/>\r\n");
                        }

                        errorNumber++;
                    }
                }
                finally {
                    if (revertPermitOnly) {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }

                sb.Append(endExpandableBlock);
                sb.Append(toggleScript);
            }
            // If it's a FileNotFoundException/FileLoadException/BadImageFormatException with a FusionLog,
            // write it out (ASURT 83587)
            if (!dontShowSensitiveInfo && Exception != null) {
                // (Only display the fusion log in medium or higher (ASURT 126827)
                if (HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Medium)) {
                    WriteFusionLogWithAssert(sb);
                }
            }

            WriteColoredSquare(sb, ColoredSquare2Title, ColoredSquare2Description, ColoredSquare2Content, false);

            if (!(dontShowSensitiveInfo || _dontShowVersion)) {  // don't show version for security reasons
                sb.Append("            <hr width=100% size=1 color=silver>\r\n\r\n");
                sb.Append("            <b>" + SR.GetString(SR.Error_Formatter_Version) + "</b>&nbsp;" +
                                       SR.GetString(SR.Error_Formatter_CLR_Build) + VersionInfo.ClrVersion +
                                       SR.GetString(SR.Error_Formatter_ASPNET_Build) + VersionInfo.EngineVersion + "\r\n\r\n");
                sb.Append("            </font>\r\n\r\n");
            }
            sb.Append("    </body>\r\n");
            sb.Append("</html>\r\n");

            sb.Append(PostMessage);

            return sb.ToString();
        }

        [PermissionSet(SecurityAction.Assert, Unrestricted=true)]
        private void WriteFusionLogWithAssert(StringBuilder sb) {
            for (Exception e = Exception; e != null; e = e.InnerException) {
                string fusionLog = null;
                string filename = null;
                FileNotFoundException fnfException = e as FileNotFoundException;
                if (fnfException != null) {
                    fusionLog = fnfException.FusionLog;
                    filename = fnfException.FileName;
                }
                FileLoadException flException = e as FileLoadException;
                if (flException != null) {
                    fusionLog = flException.FusionLog;
                    filename = flException.FileName;
                }
                BadImageFormatException bifException = e as BadImageFormatException;
                if (bifException != null) {
                    fusionLog = bifException.FusionLog;
                    filename = bifException.FileName;
                }
                if (!String.IsNullOrEmpty(fusionLog)) {
                    WriteColoredSquare(sb,
                                       SR.GetString(SR.Error_Formatter_FusionLog),
                                       SR.GetString(SR.Error_Formatter_FusionLogDesc, filename),
                                       HttpUtility.HtmlEncode(fusionLog),
                                       false /*WrapColoredSquareContentLines*/);
                    break;
                }
            }
        }

        private void WriteColoredSquare(StringBuilder sb, string title, string description,
            string content, bool wrapContentLines) {
            if (title != null) {
                sb.Append("            <b>" + title + ":</b> " + description + "<br><br>\r\n\r\n");
                sb.Append("            <table width=100% bgcolor=\"#ffffcc\">\r\n");
                sb.Append("               <tr>\r\n");
                sb.Append("                  <td>\r\n");
                sb.Append("                      <code>");
                if (!wrapContentLines)
                    sb.Append("<pre>");
                sb.Append("\r\n\r\n");
                sb.Append(content);
                if (!wrapContentLines)
                    sb.Append("</pre>");
                sb.Append("</code>\r\n\r\n");
                sb.Append("                  </td>\r\n");
                sb.Append("               </tr>\r\n");
                sb.Append("            </table>\r\n\r\n");
                sb.Append("            <br>\r\n\r\n");
            }
        }


        internal /*public*/ virtual void PrepareFormatter() {
            // VSWhidbey 139210: ErrorFormatter object might be reused and
            // the properties would be gone through again.  So we need to
            // clear the adaptive error content to avoid duplicate content.
            if (_adaptiveMiscContent != null) {
                _adaptiveMiscContent.Clear();
            }

            if (_adaptiveStackTrace != null) {
                _adaptiveStackTrace.Clear();
            }
        }

        /*
         * Return the associated exception object (if any)
         */
        protected virtual Exception Exception {
            get { return null; }
        }

        /*
         * Return the type of error.  e.g. "Compilation Error."
         */
        protected abstract string ErrorTitle {
            get;
        }

        /*
         * Return a description of the error
         * e.g. "An error occurred during the compilation of a resource required to service"
         */
        protected abstract string Description {
            get;
        }

        /*
         * A section used differently by different types of errors (title)
         * e.g. "Compiler Error Message"
         * e.g. "Exception Details"
         */
        protected abstract string MiscSectionTitle {
            get;
        }

        /*
         * A section used differently by different types of errors (content)
         * e.g. "BC30198: Expected: )"
         * e.g. "System.NullReferenceException"
         */
        protected abstract string MiscSectionContent {
            get;
        }

        /*
         * e.g. "Source Error"
         */
        protected virtual string ColoredSquareTitle {
            get { return null;}
        }

        /*
         * Optional text between color square title and the color square itself
         */
        protected virtual string ColoredSquareDescription {
            get { return null;}
        }

        /*
         * e.g. a piece of source code with the error context
         */
        protected virtual string ColoredSquareContent {
            get { return null;}
        }

        /*
         * If false, use a <pre></pre> tag around it
         */
        protected virtual bool WrapColoredSquareContentLines {
            get { return false;}
        }

        /*
         * e.g. "Source Error"
         */
        protected virtual string ColoredSquare2Title {
            get { return null;}
        }

        /*
         * Optional text between color square title and the color square itself
         */
        protected virtual string ColoredSquare2Description {
            get { return null;}
        }

        /*
         * e.g. a piece of source code with the error context
         */
        protected virtual string ColoredSquare2Content {
            get { return null;}
        }

        /*
         * Misc content which will be shown to mobile devices
         * e.g. compile error code
         */
        protected virtual StringCollection AdaptiveMiscContent {
            get {
                if (_adaptiveMiscContent == null) {
                    _adaptiveMiscContent = new StringCollection();
                }
                return _adaptiveMiscContent;
            }
        }

        /*
         * Exception stack trace which will be shown to mobile devices
         * e.g. stack trace of a runtime error
         */
        protected virtual StringCollection AdaptiveStackTrace {
            get {
                if (_adaptiveStackTrace == null) {
                    _adaptiveStackTrace = new StringCollection();
                }
                return _adaptiveStackTrace;
            }
        }

        /*
         * Determines whether SourceFileName and SourceFileLineNumber will be used
         */
        protected abstract bool ShowSourceFileInfo {
            get;
        }

        /*
         * e.g. d:\samples\designpreview\test.aspx
         */
        protected virtual string PhysicalPath {
            get { return null;}
        }

        /*
         * e.g. /myapp/test.aspx
         */
        protected virtual string VirtualPath {
            get { return null;}
        }

        /*
         * The line number in the source file
         */
        protected virtual int SourceFileLineNumber {
            get { return 0;}
        }

        protected virtual String PostMessage {
            get { return null; }
        }

        /*
         * Does this error have only information that we want to
         * show over the web to random users?
         */
        internal virtual bool CanBeShownToAllUsers {
            get { return false;}
        }

        // VSWhidbey 477678: Respect current language text format that is right
        // to left.  To be used by subclasses who need to adjust text format for
        // code area accordingly.
        protected static bool IsTextRightToLeft {
            get {
                return CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft;
            }
        }


        protected string WrapWithLeftToRightTextFormatIfNeeded(string content) {
            if (IsTextRightToLeft) {
                content = BeginLeftToRightTag + content + EndLeftToRightTag;
            }
            return content;
        }

        // Make an HTTP line pragma from a virtual path
        internal static string MakeHttpLinePragma(string virtualPath) {
            string server = "http://server";
            // We should only append a "/" if the virtual path does not
            // already start with "/". Otherwise, we end up with double
            // slashes, eg http://server//vpp/foo.aspx , and this breaks
            // the VirtualPathProvider. (DevDiv 157238)
            if (virtualPath != null && !virtualPath.StartsWith("/", StringComparison.Ordinal)) {
                server += "/";
            }

            return (new Uri(server + virtualPath)).ToString();
        }

        internal static string GetSafePath(string linePragma) {

            // First, check if it's an http line pragma
            string virtualPath = GetVirtualPathFromHttpLinePragma(linePragma);

            // If so, just return the virtual path
            if (virtualPath != null)
                return virtualPath;

            // If not, it must be a physical path, which we need to make safe
            return HttpRuntime.GetSafePath(linePragma);
        }

        internal static string GetVirtualPathFromHttpLinePragma(string linePragma) {

            if (String.IsNullOrEmpty(linePragma))
                return null;

            try {
                Uri uri = new Uri(linePragma);
                if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
                    return uri.LocalPath;
            }
            catch {}

            return null;
        }

        internal static string ResolveHttpFileName(string linePragma) {

            // When running under VS debugger, we use URL's instead of paths in our #line pragmas.
            // When we detect this situation, we need to do a MapPath to get back to the file name (ASURT 76211/114867)

            string virtualPath = GetVirtualPathFromHttpLinePragma(linePragma);

            // If we didn't detect a virtual path, just return the input
            if (virtualPath == null)
                return linePragma;

            return HostingEnvironment.MapPathInternal(virtualPath);
        }

        /*
         * This can be either a virtual or physical path, depending on what's available
         */
        private string GetDisplayPath() {

            if (VirtualPath != null)
                return VirtualPath;

            // It used to be an Assert on the following check but since
            // adaptive error rendering uses this method where both
            // VirtualPath and PhysicalPath might not set, it is changed to
            // an if statement.
            if (PhysicalPath != null)
                return HttpRuntime.GetSafePath(PhysicalPath);

            return null;
        }
    }

    /*
     * This formatter is used for runtime exceptions that don't fall into a
     * specific category.
     */
    internal class UnhandledErrorFormatter : ErrorFormatter {
        protected Exception _e;
        protected Exception _initialException;
        protected ArrayList _exStack = new ArrayList();
        protected string _physicalPath;
        protected int _line;
        private string _coloredSquare2Content;
        private bool _fGeneratedCodeOnStack;
        protected String _message;
        protected String _postMessage;

        internal UnhandledErrorFormatter(Exception e) : this(e, null, null){
        }

        internal UnhandledErrorFormatter(Exception e, String message, String postMessage) {
            _message = message;
            _postMessage = postMessage;
            _e = e;
        }

        internal /*public*/ override void PrepareFormatter() {

            // Build a stack of exceptions
            for (Exception e = _e; e != null; e = e.InnerException) {
                _exStack.Add(e);

                // Keep track of the initial exception (first one thrown)
                _initialException = e;
            }

            // Get the Square2Content first so the line number gets calculated
            _coloredSquare2Content = ColoredSquare2Content;
        }

        protected override Exception Exception {
            get { return _e; }
        }

        protected override string ErrorTitle {
            get {
                // Use the exception's message if there is one
                string msg = _initialException.Message;
                if (!String.IsNullOrEmpty(msg))
                    return HttpUtility.FormatPlainTextAsHtml(msg);

                // Otherwise, use some default string
                return SR.GetString(SR.Unhandled_Err_Error);
            }
        }

        protected override string Description {
            get {
                if (_message != null) {
                    return _message;
                }
                else {
                    return SR.GetString(SR.Unhandled_Err_Desc);
                }
            }
        }

        protected override string MiscSectionTitle {
            get { return SR.GetString(SR.Unhandled_Err_Exception_Details);}
        }

        protected override string MiscSectionContent {
            get {
                string exceptionName = _initialException.GetType().FullName;
                StringBuilder msg = new StringBuilder(exceptionName);
                string adaptiveMiscLine = exceptionName;

                if (_initialException.Message != null) {
                    string errorMessage = HttpUtility.FormatPlainTextAsHtml(_initialException.Message);
                    msg.Append(": ");
                    msg.Append(errorMessage);
                    adaptiveMiscLine += ": " + errorMessage;
                }
                AdaptiveMiscContent.Add(adaptiveMiscLine);

                if (_initialException is UnauthorizedAccessException) {
                    msg.Append("\r\n<br><br>");
                    String errDesc = SR.GetString(SR.Unauthorized_Err_Desc1);
                    errDesc = HttpUtility.HtmlEncode(errDesc);
                    msg.Append(errDesc);
                    AdaptiveMiscContent.Add(errDesc);

                    msg.Append("\r\n<br><br>");
                    errDesc = SR.GetString(SR.Unauthorized_Err_Desc2);
                    errDesc = HttpUtility.HtmlEncode(errDesc);
                    msg.Append(errDesc);
                    AdaptiveMiscContent.Add(errDesc);
                }
                else if (_initialException is HostingEnvironmentException) {
                    String details = ((HostingEnvironmentException)_initialException).Details;

                    if (!String.IsNullOrEmpty(details)) {
                        msg.Append("\r\n<br><br><b>");
                        msg.Append(details);
                        msg.Append("</b>");
                        AdaptiveMiscContent.Add(details);
                    }
                }

                return msg.ToString();
            }
        }

        protected override string ColoredSquareTitle {
            get { return SR.GetString(SR.TmplCompilerSourceSecTitle);}
        }

        protected override string ColoredSquareContent {
            get {

                // If we couldn't get line info for the error, display a standard message
                if (_physicalPath == null) {

                    const string BeginLeftToRightMarker = "BeginMarker";
                    const string EndLeftToRightMarker = "EndMarker";
                    bool setLeftToRightMarker = false;

                    // The error text depends on whether .aspx code was found on the stack
                    // Also, if trust is less than medium, never display the message that
                    // explains how to turn on debugging, since it's not allowed (Whidbey 9176)
                    string msg;
                    if (!_fGeneratedCodeOnStack ||
                        !HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Medium)) {
                        msg = SR.GetString(SR.Src_not_available_nodebug);
                    }
                    else {
                        if (IsTextRightToLeft) {
                            setLeftToRightMarker = true;
                        }

                        // Because the resource string has both normal language text and config/code samples,
                        // left-to-right markup tags need to be wrapped around the config/code samples if
                        // right to left language format is being used.
                        //
                        // Note that the retrieved resource string will be passed to the call
                        // HttpUtility.FormatPlainTextAsHtml(), which does HtmlEncode.  In order to preserve
                        // the left-to-right markup tags, the resource string has been added with markers
                        // that identify the beginnings and ends of config/code samples.  After
                        // FormatPlainTextAsHtml() is called, and the markers will be replaced with
                        // left-to-right markup tags below.
                        msg = SR.GetString(SR.Src_not_available,
                                           ((setLeftToRightMarker) ? BeginLeftToRightMarker : string.Empty),
                                           ((setLeftToRightMarker) ? EndLeftToRightMarker : string.Empty),
                                           ((setLeftToRightMarker) ? BeginLeftToRightMarker : string.Empty),
                                           ((setLeftToRightMarker) ? EndLeftToRightMarker : string.Empty));
                    }

                    msg = HttpUtility.FormatPlainTextAsHtml(msg);

                    if (setLeftToRightMarker) {
                        // If only <div dir=ltr> was used to wrap around the left-to-right code text,
                        // the font rendering on Firefox was not good.  We use <code> in addition to
                        // the <div> tag to workaround the problem.
                        const string BeginLeftToRightTags = "</code>" + BeginLeftToRightTag + "<code>";
                        const string EndLeftToRightTags = "</code>" + EndLeftToRightTag + "<code>";
                        msg = msg.Replace(BeginLeftToRightMarker, BeginLeftToRightTags);
                        msg = msg.Replace(EndLeftToRightMarker, EndLeftToRightTags);
                    }

                    return msg;
                }

                return FormatterWithFileInfo.GetSourceFileLines(_physicalPath, Encoding.Default, null, _line);
            }
        }

        protected override bool WrapColoredSquareContentLines {
            // Only wrap the text if we're displaying the standard message
            get { return (_physicalPath == null);}
        }

        protected override string ColoredSquare2Title {
            get { return SR.GetString(SR.Unhandled_Err_Stack_Trace);}
        }

        protected override string ColoredSquare2Content {
            get {
                if (_coloredSquare2Content != null)
                    return _coloredSquare2Content;

                StringBuilder sb = new StringBuilder();
                bool addAdaptiveStackTrace = true;
                int sbBeginIndex = 0;

                for (int i = _exStack.Count - 1; i >=0; i--) {
                    if (i < _exStack.Count - 1)
                        sb.Append("\r\n");

                    Exception e = (Exception)_exStack[i];

                    sb.Append("[" + _exStack[i].GetType().Name);

                    // Display the error code if there is one
                    if ((e is ExternalException) && ((ExternalException) e).ErrorCode != 0)
                        sb.Append(" (0x" + (((ExternalException)e).ErrorCode).ToString("x", CultureInfo.CurrentCulture) + ")");

                    // Display the message if there is one
                    if (e.Message != null && e.Message.Length > 0)
                        sb.Append(": " + e.Message);

                    sb.Append("]\r\n");

                    // Display the stack trace
                    StackTrace st = new StackTrace(e, true /*fNeedFileInfo*/);
                    for (int j = 0; j < st.FrameCount; j++) {

                        if (addAdaptiveStackTrace) {
                            sbBeginIndex = sb.Length;
                        }
                        StackFrame sf = st.GetFrame(j);

                        MethodBase mb = sf.GetMethod();
                        Type declaringType = mb.DeclaringType;
                        string ns = String.Empty;
                        if (declaringType != null) {

                            // Check if this stack item is for ASP generated code (ASURT 51063).
                            // To do this, we check if the assembly lives in the codegen dir.
                            // But if the native offset is 0, it is likely that the method simply
                            // failed to JIT, in which case don't treat it as an ASP.NET stack,
                            // since no line number can ever be shown for it (VSWhidbey 87014).
                            string assemblyDir = null;
                            try {
                                // This could throw if the assembly is dynamic
                                assemblyDir = System.Web.UI.Util.GetAssemblyCodeBase(declaringType.Assembly);
                            }
                            catch {}

                            if (assemblyDir != null) {
                                assemblyDir = Path.GetDirectoryName(assemblyDir);
                                if (string.Compare(assemblyDir, HttpRuntime.CodegenDirInternal,
                                    StringComparison.OrdinalIgnoreCase) == 0 && sf.GetNativeOffset() > 0) {
                                    _fGeneratedCodeOnStack = true;
                                }
                            }

                            ns = declaringType.Namespace;
                        }

                        if (ns != null)
                            ns = ns + ".";

                        if (declaringType == null) {
                            sb.Append("   " + mb.Name + "(");
                        }
                        else {
                            sb.Append("   " + ns + declaringType.Name + "." +
                                mb.Name + "(");
                        }

                        ParameterInfo[] arrParams = mb.GetParameters();

                        for (int k = 0; k < arrParams.Length; k++) {
                            sb.Append((k != 0 ? ", " : String.Empty) + arrParams[k].ParameterType.Name + " " +
                                arrParams[k].Name);
                        }

                        sb.Append(")");

                        string fileName = GetFileName(sf);
                        if (fileName != null) {

                            // ASURT 114867: if it's an http path, turn it into a local path
                            fileName = ResolveHttpFileName(fileName);
                            if (fileName != null) {

                                // Remember the file/line number of the top level stack
                                // item for which we have symbols
                                if (_physicalPath == null && FileUtil.FileExists(fileName)) {
                                    _physicalPath = fileName;

                                    _line = sf.GetFileLineNumber();
                                }

                                sb.Append(" in " + HttpRuntime.GetSafePath(fileName) +
                                    ":" + sf.GetFileLineNumber());
                            }
                        }
                        else {
                            sb.Append(" +" + sf.GetNativeOffset());
                        }

                        if (addAdaptiveStackTrace) {
                            string stackTraceText = sb.ToString(sbBeginIndex,
                                                                sb.Length - sbBeginIndex);
                            AdaptiveStackTrace.Add(HttpUtility.HtmlEncode(stackTraceText));
                        }

                        sb.Append("\r\n");
                    }
                    // Due to size limitation, we only want to add the top
                    // stack trace for mobile devices.
                    addAdaptiveStackTrace = false;
                }

                _coloredSquare2Content = HttpUtility.HtmlEncode(sb.ToString());

                _coloredSquare2Content = WrapWithLeftToRightTextFormatIfNeeded(_coloredSquare2Content);

                return _coloredSquare2Content;
            }
        }

        // Dev10 786146: partial trust apps may not have PathDiscovery, so just pretend
        // the path is unknown.
        private string GetFileName(StackFrame sf) {
            string fileName = null;
            try {
                fileName = sf.GetFileName();
            }
            catch (SecurityException) {
            }
            return fileName;
        }

        protected override String PostMessage {
            get { return _postMessage; }
        }

        protected override bool ShowSourceFileInfo {
            get { return _physicalPath != null; }
        }

        protected override string PhysicalPath {
            get { return _physicalPath; }
        }

        protected override int SourceFileLineNumber {
            get { return _line; }
        }
    }

    /*
     * This formatter is used for security exceptions.
     */
    internal class SecurityErrorFormatter : UnhandledErrorFormatter {

        internal SecurityErrorFormatter(Exception e) : base(e) {}

        protected override string ErrorTitle {
            get {
                return SR.GetString(SR.Security_Err_Error);
            }
        }

        protected override string Description {
            get {
                // VSWhidbey 493720: Do Html encode to preserve space characters
                return HttpUtility.FormatPlainTextAsHtml(SR.GetString(SR.Security_Err_Desc));
            }
        }
    }

    /*
     * This formatter is used for 404: page not found errors
     */
    internal class PageNotFoundErrorFormatter : ErrorFormatter {
        protected string _htmlEncodedUrl;
        private StringCollection _adaptiveMiscContent = new StringCollection();

        internal PageNotFoundErrorFormatter(string url) {
            _htmlEncodedUrl = HttpUtility.HtmlEncode(url);
            _adaptiveMiscContent.Add(_htmlEncodedUrl);
        }

        protected override string ErrorTitle {
            get { return SR.GetString(SR.NotFound_Resource_Not_Found);}
        }

        protected override string Description {
            get { return HttpUtility.FormatPlainTextAsHtml(SR.GetString(SR.NotFound_Http_404));}
        }

        protected override string MiscSectionTitle {
            get { return SR.GetString(SR.NotFound_Requested_Url);}
        }

        protected override string MiscSectionContent {
            get { return _htmlEncodedUrl;}
        }

        protected override StringCollection AdaptiveMiscContent {
            get { return _adaptiveMiscContent;}
        }

        protected override bool ShowSourceFileInfo {
            get { return false;}
        }

        internal override bool CanBeShownToAllUsers {
            get { return true;}
        }
    }

    /*
     * This formatter is used for 403: forbidden
     */
    internal class PageForbiddenErrorFormatter : ErrorFormatter {
        protected string _htmlEncodedUrl;
        private StringCollection _adaptiveMiscContent = new StringCollection();
        private string _description;

        internal PageForbiddenErrorFormatter(string url): this(url, null) {
        }

        internal PageForbiddenErrorFormatter(string url, string description) {
            _htmlEncodedUrl = HttpUtility.HtmlEncode(url);
            _adaptiveMiscContent.Add(_htmlEncodedUrl);
            _description = description;
        }

        protected override string ErrorTitle {
            get { return SR.GetString(SR.Forbidden_Type_Not_Served);}
        }

        protected override string Description {
            get {
                if (_description != null) {
                    return _description;
                }
                Match m = Regex.Match(_htmlEncodedUrl, @"\.\w+$");

                String extMessage = String.Empty;

                if (m.Success)
                    extMessage = SR.GetString(SR.Forbidden_Extension_Incorrect, m.ToString());

                return HttpUtility.FormatPlainTextAsHtml(SR.GetString(SR.Forbidden_Extension_Desc, extMessage));
            }
        }

        protected override string MiscSectionTitle {
            get { return SR.GetString(SR.NotFound_Requested_Url);}
        }

        protected override string MiscSectionContent {
            get { return _htmlEncodedUrl;}
        }

        protected override StringCollection AdaptiveMiscContent {
            get { return _adaptiveMiscContent;}
        }

        protected override bool ShowSourceFileInfo {
            get { return false;}
        }

        internal override bool CanBeShownToAllUsers {
            get { return true;}
        }
    }

    /*
     * This formatter is used for generic errors that hide sensitive information
     * error text is sometimes different for remote vs. local machines
     */
    internal class GenericApplicationErrorFormatter : ErrorFormatter {
        private bool _local;

        internal GenericApplicationErrorFormatter(bool local) {
            _local = local;
        }

        protected override string ErrorTitle {
            get {
                return SR.GetString(SR.Generic_Err_Title);
            }
        }

        protected override string Description {
            get {
                return SR.GetString(
                                    _local ? SR.Generic_Err_Local_Desc
                                           : SR.Generic_Err_Remote_Desc);
            }
        }

        protected override string MiscSectionTitle {
            get {
                return null;
            }
        }

        protected override string MiscSectionContent {
            get {
                return null;
            }
        }

        protected override string ColoredSquareTitle {
            get {
                String detailsTitle = SR.GetString(SR.Generic_Err_Details_Title);
                AdaptiveMiscContent.Add(detailsTitle);
                return detailsTitle;
            }
        }

        protected override string ColoredSquareDescription {
            get {
                String detailsDesc = SR.GetString(
                                    _local ? SR.Generic_Err_Local_Details_Desc
                                           : SR.Generic_Err_Remote_Details_Desc);
                detailsDesc = HttpUtility.HtmlEncode(detailsDesc);
                AdaptiveMiscContent.Add(detailsDesc);
                return detailsDesc;
            }
        }

        protected override string ColoredSquareContent {
            get {
                string content = HttpUtility.HtmlEncode(SR.GetString(
                                    _local ? SR.Generic_Err_Local_Details_Sample
                                           : SR.Generic_Err_Remote_Details_Sample));

                return (WrapWithLeftToRightTextFormatIfNeeded(content));
            }
        }

        protected override string ColoredSquare2Title {
            get {
                String noteTitle = SR.GetString(SR.Generic_Err_Notes_Title);
                AdaptiveMiscContent.Add(noteTitle);
                return noteTitle;
            }
        }

        protected override string ColoredSquare2Description {
            get {
                String notesDesc = SR.GetString(SR.Generic_Err_Notes_Desc);
                notesDesc = HttpUtility.HtmlEncode(notesDesc);
                AdaptiveMiscContent.Add(notesDesc);
                return notesDesc;
            }
        }

        protected override string ColoredSquare2Content {
            get {
                string content = HttpUtility.HtmlEncode(SR.GetString(
                                    _local ? SR.Generic_Err_Local_Notes_Sample
                                           : SR.Generic_Err_Remote_Notes_Sample));

                return (WrapWithLeftToRightTextFormatIfNeeded(content));
            }
        }

        protected override bool ShowSourceFileInfo {
            get { return false;}
        }

        internal override bool CanBeShownToAllUsers {
            get { return true;}
        }
    }

    /*
    * This formatter is used when we couldn't run the normal custom error page (due to it also failing)
    */
    internal class CustomErrorFailedErrorFormatter : ErrorFormatter {
        internal CustomErrorFailedErrorFormatter() {
        }

        protected override string ErrorTitle {
            get { return SR.GetString(SR.Generic_Err_Title); }
        }

        protected override string Description {
            get { return HttpUtility.FormatPlainTextAsHtml(SR.GetString(SR.CustomErrorFailed_Err_Desc)); }
        }

        protected override string MiscSectionTitle {
            get { return null; }
        }

        protected override string MiscSectionContent {
            get { return null; }
        }

        protected override bool ShowSourceFileInfo {
            get { return false; }
        }

        internal override bool CanBeShownToAllUsers {
            get { return true; }
        }
    }


    /*
     * This is the base class for formatter that handle errors that have an
     * associated file / line number.
     */
    internal abstract class FormatterWithFileInfo : ErrorFormatter {
        protected string _virtualPath;
        protected string _physicalPath;
        protected string _sourceCode;
        protected int _line;

        // Number of lines before and after the error lines included in the report
        private const int errorRange = 2;

        /*
         * Return the text of the error line in the source file, with a few
         * lines around it.  It is returned in HTML format.
         */
        internal static string GetSourceFileLines(string fileName, Encoding encoding, string sourceCode, int lineNumber) {

            // Don't show any source file if the user doesn't have access to it (ASURT 122430)
            if (fileName != null && !HttpRuntime.HasFilePermission(fileName))
                return SR.GetString(SR.WithFile_No_Relevant_Line);

            // 
            StringBuilder sb = new StringBuilder();

            if (lineNumber <= 0) {
                return SR.GetString(SR.WithFile_No_Relevant_Line);
            }

            TextReader reader = null;

            // Check if it's an http line pragma, from which we can get a VirtualPath
            string virtualPath = GetVirtualPathFromHttpLinePragma(fileName);

            // If we got a virtual path, open a TextReader from it
            if (virtualPath != null) {
                Stream stream = VirtualPathProvider.OpenFile(virtualPath);
                if (stream != null)
                    reader = System.Web.UI.Util.ReaderFromStream(stream, System.Web.VirtualPath.Create(virtualPath));
            }

            try {
                // Otherwise, open the physical file
                if (reader == null && fileName != null)
                    reader = new StreamReader(fileName, encoding, true, 4096);
            }
            catch { }

            if (reader == null) {
                if (sourceCode == null)
                    return SR.GetString(SR.WithFile_No_Relevant_Line);

                // Can't open the file?  Use the dynamically generated content...
                reader = new StringReader(sourceCode);
            }

            try {
                bool fFoundLine = false;

                if (IsTextRightToLeft) {
                    sb.Append(BeginLeftToRightTag);
                }

                for (int i=1; ; i++) {
                    // Get the current line from the source file
                    string sourceLine = reader.ReadLine();
                    if (sourceLine == null)
                        break;

                    // If it's the error line, make it red
                    if (i == lineNumber)
                        sb.Append("<font color=red>");

                    // Is it in the range we want to display
                    if (i >= lineNumber-errorRange && i <= lineNumber+errorRange) {
                        fFoundLine = true;
                        String linestr = i.ToString("G", CultureInfo.CurrentCulture);

                        sb.Append(SR.GetString(SR.WithFile_Line_Num, linestr));
                        if (linestr.Length < 3)
                            sb.Append(' ', 3 - linestr.Length);
                        sb.Append(HttpUtility.HtmlEncode(sourceLine));

                        if (i != lineNumber+errorRange)
                            sb.Append("\r\n");
                    }

                    if (i == lineNumber)
                        sb.Append("</font>");

                    if (i>lineNumber+errorRange)
                        break;
                }

                if (IsTextRightToLeft) {
                    sb.Append(EndLeftToRightTag);
                }

                if (!fFoundLine)
                    return SR.GetString(SR.WithFile_No_Relevant_Line);
            }
            finally {
                // Make sure we always close the reader
                reader.Close();
            }

            return sb.ToString();
        }

        private string GetSourceFileLines() {
            return GetSourceFileLines(_physicalPath, SourceFileEncoding, _sourceCode, _line);
        }

        internal FormatterWithFileInfo(string virtualPath, string physicalPath,
            string sourceCode, int line) {

            _virtualPath = virtualPath;
            _physicalPath = physicalPath;

            if (sourceCode == null && _physicalPath == null && _virtualPath != null) {

                // Make sure _virtualPath is really a virtual path.  Sometimes,
                // it can actually be a physical path, in which case we keep
                // it as is.
                if (UrlPath.IsValidVirtualPathWithoutProtocol(_virtualPath))
                    _physicalPath = HostingEnvironment.MapPath(_virtualPath);
                else
                    _physicalPath = _virtualPath;
            }

            _sourceCode = sourceCode;
            _line = line;
        }

        protected virtual Encoding SourceFileEncoding {
            get { return Encoding.Default; }
        }

        protected override string ColoredSquareContent {
            get { return GetSourceFileLines();}
        }

        protected override bool ShowSourceFileInfo {
            get { return true;}
        }

        protected override string PhysicalPath {
            get { return _physicalPath;}
        }

        protected override string VirtualPath {
            get { return _virtualPath;}
        }

        protected override int SourceFileLineNumber {
            get { return _line;}
        }
    }

    /*
     * Formatter used for compilation errors
     */
    internal class DynamicCompileErrorFormatter : ErrorFormatter {

        private const string startExpandableBlock =
            "<br><div class=\"expandable\" onclick=\"OnToggleTOCLevel1('{0}')\">" +
            "{1}" +
            ":</div>\r\n" +
            "<div id=\"{0}\" style=\"display: none;\">\r\n" +
            "            <br><table width=100% bgcolor=\"#ffffcc\">\r\n" +
            "               <tr>\r\n" +
            "                  <td>\r\n" +
            "                      <code><pre>\r\n\r\n";

        private const string endExpandableBlock =
            "</pre></code>\r\n\r\n" +
            "                  </td>\r\n" +
            "               </tr>\r\n" +
            "            </table>\r\n\r\n" +
            "            \r\n\r\n" +
            "</div>\r\n";

        // Number of lines before and after the error lines included in the report
        private const int errorRange = 2;

        HttpCompileException _excep;
        private string _sourceFilePath = null;
        private int _sourceFileLineNumber = 0;
        protected bool _hideDetailedCompilerOutput = false;

        internal DynamicCompileErrorFormatter(HttpCompileException excep) {
            _excep = excep;
        }

        protected override Exception Exception {
            get { return _excep; }
        }

        protected override bool ShowSourceFileInfo {
            get {
                return false;
            }
        }

        protected override string ErrorTitle {
            get {
                return SR.GetString(SR.TmplCompilerErrorTitle);
            }
        }

        protected override string Description {
            get {
                return SR.GetString(SR.TmplCompilerErrorDesc);
            }
        }

        protected override string MiscSectionTitle {
            get {
                return SR.GetString(SR.TmplCompilerErrorSecTitle);
            }
        }

        protected override string MiscSectionContent {
            get {
                StringBuilder sb = new StringBuilder(128);

                CompilerResults results = _excep.ResultsWithoutDemand;

                // Handle fatal errors where we couldn't find an error line
                if (results.Errors.Count == 0 && results.NativeCompilerReturnValue != 0) {
                    string fatalError = SR.GetString(SR.TmplCompilerFatalError,
                                            results.NativeCompilerReturnValue.ToString("G",
                                                CultureInfo.CurrentCulture));
                    AdaptiveMiscContent.Add(fatalError);
                    sb.Append(fatalError);
                    sb.Append("<br><br>\r\n");
                }

                if (results.Errors.HasErrors) {

                    CompilerError e = _excep.FirstCompileError;

                    if (e != null) {
                        string htmlEncodedText = HttpUtility.HtmlEncode(e.ErrorNumber);
                        string adaptiveContentLine = htmlEncodedText;
                        sb.Append(htmlEncodedText);
                        // Don't show the error message in low trust (VSWhidbey 87012)
                        if (HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Medium)) {
                            htmlEncodedText = HttpUtility.HtmlEncode(e.ErrorText);
                            sb.Append(": ");
                            sb.Append(htmlEncodedText);
                            adaptiveContentLine += ": " + htmlEncodedText;
                        }
                        AdaptiveMiscContent.Add(adaptiveContentLine);
                        sb.Append("<br><br>\r\n");

                        sb.Append("<b>");
                        sb.Append(SR.GetString(SR.TmplCompilerSourceSecTitle));
                        sb.Append(":</b><br><br>\r\n");
                        sb.Append("            <table width=100% bgcolor=\"#ffffcc\">\r\n");
                        sb.Append("               <tr><td>\r\n");
                        sb.Append("               ");
                        sb.Append("               </td></tr>\r\n");
                        sb.Append("               <tr>\r\n");
                        sb.Append("                  <td>\r\n");
                        sb.Append("                      <code><pre>\r\n\r\n");
                        sb.Append(FormatterWithFileInfo.GetSourceFileLines(e.FileName, Encoding.Default, _excep.SourceCodeWithoutDemand, e.Line));
                        sb.Append("</pre></code>\r\n\r\n");
                        sb.Append("                  </td>\r\n");
                        sb.Append("               </tr>\r\n");
                        sb.Append("            </table>\r\n\r\n");
                        sb.Append("            <br>\r\n\r\n");

                        // display file
                        sb.Append("            <b>");
                        sb.Append(SR.GetString(SR.TmplCompilerSourceFileTitle));
                        sb.Append(":</b> ");
                        _sourceFilePath = GetSafePath(e.FileName);
                        sb.Append(HttpUtility.HtmlEncode(_sourceFilePath));
                        sb.Append("\r\n");

                        // display number
                        TypeConverter itc = new Int32Converter();
                        sb.Append("            &nbsp;&nbsp; <b>");
                        sb.Append(SR.GetString(SR.TmplCompilerSourceFileLine));
                        sb.Append(":</b>  ");
                        _sourceFileLineNumber = e.Line;
                        sb.Append(HttpUtility.HtmlEncode(itc.ConvertToString(_sourceFileLineNumber)));
                        sb.Append("\r\n");
                        sb.Append("            <br><br>\r\n");
                    }
                }

                if (results.Errors.HasWarnings) {
                    sb.Append("<br><div class=\"expandable\" onclick=\"OnToggleTOCLevel1('warningDiv')\">");
                    sb.Append(SR.GetString(SR.TmplCompilerWarningBanner));
                    sb.Append(":</div>\r\n");
                    sb.Append("<div id=\"warningDiv\" style=\"display: none;\">\r\n");
                    foreach (CompilerError e in results.Errors) {
                        if (e.IsWarning) {
                            sb.Append("<b>");
                            sb.Append(SR.GetString(SR.TmplCompilerWarningSecTitle));
                            sb.Append(":</b> ");
                            sb.Append(HttpUtility.HtmlEncode(e.ErrorNumber));
                            // Don't show the error message in low trust (VSWhidbey 87012)
                            if (HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Medium)) {
                                sb.Append(": ");
                                sb.Append(HttpUtility.HtmlEncode(e.ErrorText));
                            }
                            sb.Append("<br>\r\n");

                            sb.Append("<b>");
                            sb.Append(SR.GetString(SR.TmplCompilerSourceSecTitle));
                            sb.Append(":</b><br><br>\r\n");
                            sb.Append("            <table width=100% bgcolor=\"#ffffcc\">\r\n");
                            sb.Append("               <tr><td>\r\n");
                            sb.Append("               <b>");
                            sb.Append(HttpUtility.HtmlEncode(HttpRuntime.GetSafePath(e.FileName)));
                            sb.Append("</b>\r\n");
                            sb.Append("               </td></tr>\r\n");
                            sb.Append("               <tr>\r\n");
                            sb.Append("                  <td>\r\n");
                            sb.Append("                      <code><pre>\r\n\r\n");
                            sb.Append(FormatterWithFileInfo.GetSourceFileLines(e.FileName, Encoding.Default, _excep.SourceCodeWithoutDemand, e.Line));
                            sb.Append("</pre></code>\r\n\r\n");
                            sb.Append("                  </td>\r\n");
                            sb.Append("               </tr>\r\n");
                            sb.Append("            </table>\r\n\r\n");
                            sb.Append("            <br>\r\n\r\n");
                        }
                    }
                    sb.Append("</div>\r\n");
                }

                if (!_hideDetailedCompilerOutput) {
                    if (results.Output.Count > 0) {
                        // (Only display the compiler output in medium or higher (ASURT 126827)
                        if (HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Medium)) {
                            sb.Append(String.Format(CultureInfo.CurrentCulture, startExpandableBlock, "compilerOutputDiv",
                                SR.GetString(SR.TmplCompilerCompleteOutput)));
                            foreach (string line in results.Output) {
                                sb.Append(HttpUtility.HtmlEncode(line));
                                sb.Append("\r\n");
                            }
                            sb.Append(endExpandableBlock);
                        }
                    }

                    // If we have the generated source code, display it
                    // (Only display the source in medium or higher (ASURT 128039)
                    if (_excep.SourceCodeWithoutDemand != null &&
                        HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Medium)) {

                        sb.Append(String.Format(CultureInfo.CurrentCulture, startExpandableBlock, "dynamicCodeDiv",
                            SR.GetString(SR.TmplCompilerGeneratedFile)));

                        string[] sourceLines = _excep.SourceCodeWithoutDemand.Split('\n');
                        int currentLine = 1;
                        foreach (string s in sourceLines) {
                            string number = currentLine.ToString("G", CultureInfo.CurrentCulture);
                            sb.Append(SR.GetString(SR.TmplCompilerLineHeader, number));
                            if (number.Length < 5) {
                                sb.Append(' ', 5 - number.Length);
                            }
                            currentLine++;

                            sb.Append(HttpUtility.HtmlEncode(s));
                        }
                        sb.Append(endExpandableBlock);
                    }

                    sb.Append(@"
    <script type=""text/javascript"">
    function OnToggleTOCLevel1(level2ID)
    {
      var elemLevel2 = document.getElementById(level2ID);
      if (elemLevel2.style.display == 'none')
      {
        elemLevel2.style.display = '';
      }
      else {
        elemLevel2.style.display = 'none';
      }
    }
    </script>
                          ");
                }

                return sb.ToString();
            }
        }

        // This is calculated in MiscSectionContent
        protected override string PhysicalPath {
            get { return _sourceFilePath;}
        }

        protected override int SourceFileLineNumber {
            get { return _sourceFileLineNumber;}
        }
    }

    /*
     * Formatter used for parse errors
     */
    internal class ParseErrorFormatter : FormatterWithFileInfo {
        protected string _message;
        HttpParseException _excep;
        private StringCollection _adaptiveMiscContent = new StringCollection();

        internal ParseErrorFormatter(HttpParseException e, string virtualPath,
            string sourceCode, int line, string message)
        : base(virtualPath, null /*physicalPath*/, sourceCode, line) {
            _excep = e;
            _message = HttpUtility.FormatPlainTextAsHtml(message);
            _adaptiveMiscContent.Add(_message);
        }

        protected override Exception Exception {
            get { return _excep; }
        }

        protected override string ErrorTitle {
            get { return SR.GetString(SR.Parser_Error);}
        }

        protected override string Description {
            get { return SR.GetString(SR.Parser_Desc);}
        }

        protected override string MiscSectionTitle {
            get { return SR.GetString(SR.Parser_Error_Message);}
        }

        protected override string MiscSectionContent {
            get { return _message;}
        }

        protected override string ColoredSquareTitle {
            get { return SR.GetString(SR.Parser_Source_Error);}
        }

        protected override StringCollection AdaptiveMiscContent {
            get { return _adaptiveMiscContent;}
        }
    }

    /*
     * Formatter used for configuration errors
     */
    internal class ConfigErrorFormatter : FormatterWithFileInfo {
        protected string _message;
        private Exception _e;
        private StringCollection _adaptiveMiscContent = new StringCollection();
        private bool _allowSourceCode;

        internal ConfigErrorFormatter(System.Configuration.ConfigurationException e)
        : base(null /*virtualPath*/, e.Filename, null, e.Line) {
            _e = e;
            PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_PRE_PROCESSING);
            PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_TOTAL);
            _message = HttpUtility.FormatPlainTextAsHtml(e.BareMessage);
            _adaptiveMiscContent.Add(_message);
        }

        public bool AllowSourceCode {
            get { return _allowSourceCode; }
            set { _allowSourceCode = value; }
        }

        protected override Encoding SourceFileEncoding {
            get { return Encoding.UTF8; }
        }

        protected override Exception Exception {
            get { return _e; }
        }

        protected override string ErrorTitle {
            get { return SR.GetString(SR.Config_Error);}
        }

        protected override string Description {
            get { return SR.GetString(SR.Config_Desc);}
        }

        protected override string MiscSectionTitle {
            get { return SR.GetString(SR.Parser_Error_Message);}
        }

        protected override string MiscSectionContent {
            get { return _message;}
        }

        protected override string ColoredSquareTitle {
            get { return SR.GetString(SR.Parser_Source_Error);}
        }

        protected override StringCollection AdaptiveMiscContent {
            get { return _adaptiveMiscContent;}
        }

        protected override string ColoredSquareContent {
            get {
                if (!AllowSourceCode) {
                    return SR.GetString(SR.Generic_Err_Remote_Desc);
                }

                return base.ColoredSquareContent;
            }
        }
    }

    /*
     * Formatter to allow user-specified description strings
     * use if showing inner-most exception message is not appropriate
     */
    internal class UseLastUnhandledErrorFormatter : UnhandledErrorFormatter {

        internal UseLastUnhandledErrorFormatter(Exception e)
            : base(e) {
        }

        internal /*public*/ override void PrepareFormatter() {
            base.PrepareFormatter();

            // use the outer-most exception instead of the inner-most in the misc section
            _initialException = Exception;
        }
    }

    internal class StaticErrorFormatterHelper {
        internal const string ChtmlErrorBeginTemplate = @"<html>
<body>
<form>
<font color=""Red"" size=""5"">{0}</font><br/>
<font color=""Maroon"">{1}</font><br/>
";
        internal const string ChtmlErrorEndTemplate = @"</form>
</body>
</html>";

        internal const string WmlErrorBeginTemplate = @"<?xml version='1.0'?>
<!DOCTYPE wml PUBLIC '-//WAPFORUM//DTD WML 1.1//EN' 'http://www.wapforum.org/DTD/wml_1.1.xml'><wml><head>
<meta http-equiv=""Cache-Control"" content=""max-age=0"" forua=""true""/>
</head>
<card>
<p>
<b><big>{0}</big></b><br/>
<b><i>{1}</i></b><br/>
";
        internal const string WmlErrorEndTemplate = @"</p>
</card>
</wml>
";

        internal const string XhtmlErrorBeginTemplate = @"<?xml version=""1.0"" encoding=""utf-8""?>
<!DOCTYPE html PUBLIC ""-//WAPFORUM//DTD XHTML Mobile 1.0//EN"" ""http://www.wapforum.org/DTD/xhtml-mobile10.dtd"">
<html xmlns=""http://www.w3.org/1999/xhtml"">
<head>
<title></title>
</head>
<body>
<form>
<div>
<span style=""color:Red;font-size:Large;font-weight:bold;"">{0}</span><br/>
<span style=""color:Maroon;font-weight:bold;font-style:italic;"">{1}</span><br/>
";
        internal const string XhtmlErrorEndTemplate = @"</div>
</form>
</body>
</html>";
        internal const string Break = "<br/>\r\n";
    }
}