ywuwgij / elmah

Automatically exported from code.google.com/p/elmah
Apache License 2.0
0 stars 0 forks source link

Logging fails when error contains invalid characters for XML 1.0 #43

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am using a web grid that was crashing and I was wondering why the error 
wasn't being logged.  After some investigation I found it is throwing an 
exception

System.ArgumentException was unhandled by user code
  Message="'', hexadecimal value 0x01, is an invalid character."
  Source="System.Xml"

And the value of the string being written (I am using Infragistics 
UltraWebGrid)

ChangedCellsUltraWebGrid1rc_9_1zzUltraWebGrid1rc_9_2zzActiveCellUltra
WebGrid1rc_9_2

Died on [assembly: Elmah.Scc("$Id: HttpValuesCollection.cs 25 2007-05-04 
23:24:03Z azizatif $")] line 146
 writer.WriteEndElement();

---------------------------------------------------------------------------
Exception Details

System.ArgumentException was unhandled by user code
  Message="'', hexadecimal value 0x01, is an invalid character."
  Source="System.Xml"
  StackTrace:
       at System.Xml.XmlEncodedRawTextWriter.InvalidXmlChar(Int32 ch, 
Char* pDst, Boolean entitize)
       at System.Xml.XmlEncodedRawTextWriter.WriteAttributeTextBlock(Char* 
pSrc, Char* pSrcEnd)
       at System.Xml.XmlEncodedRawTextWriter.WriteString(String text)
       at System.Xml.XmlEncodedRawTextWriterIndent.WriteString(String text)
       at System.Xml.XmlWellFormedWriter.WriteString(String text)
       at System.Xml.XmlWriter.WriteAttributeString(String localName, 
String value)
       at Elmah.HttpValuesCollection.Elmah.IXmlExportable.ToXml(XmlWriter 
writer)
       at Elmah.Error.WriteCollection(XmlWriter writer, String name, 
NameValueCollection collection)
       at Elmah.Error.WriteInnerXml(XmlWriter writer)
       at Elmah.Error.ToXml(XmlWriter writer)
       at Elmah.SqlErrorLog.Log(Error error)
       at WebSettings.DataOperation.UpdateXmlByValueDescription(DataSet 
ds, String xml) in e:\Userdata\sameera\Dev2.7
\App_Code\Settings\DataOperation.cs:line 433
       at WebSettings.subLocationList.Update() in 
e:\Userdata\sameera\Dev2.7\Settings\subLocationList.aspx.cs:line 480
       at WebSettings.subLocationList.btnSave_Click(Object sender, 
EventArgs e) in e:\Userdata\sameera\Dev2.7
\Settings\subLocationList.aspx.cs:line 113
       at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)
       at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String 
eventArgument)
       at 
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.Ra
isePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler 
sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 
postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean 
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
---------------------------------------------------------------------------

Call stack
    [External Code] 
    Elmah.DLL!Elmah.HttpValuesCollection.Elmah.IXmlExportable.ToXml
(System.Xml.XmlWriter writer = {System.Xml.XmlWellFormedWriter}) Line 146
    C#
>   Elmah.DLL!Elmah.Error.WriteCollection(System.Xml.XmlWriter writer 
= {System.Xml.XmlWellFormedWriter}, string name = "form", 
System.Collections.Specialized.NameValueCollection collection = 
{Elmah.HttpValuesCollection}) Line 488  C#
    Elmah.DLL!Elmah.Error.WriteInnerXml(System.Xml.XmlWriter writer = 
{System.Xml.XmlWellFormedWriter}) Line 475 + 0x11 bytes C#
    Elmah.DLL!Elmah.Error.ToXml(System.Xml.XmlWriter writer = 
{System.Xml.XmlWellFormedWriter}) Line 439  C#
    Elmah.DLL!Elmah.SqlErrorLog.Log(Elmah.Error error = {Access to the 
path 'E:\Userdata\sameera\Dev2.7\Configuration\LocationList.xml' is 
denied.}) Line 170  C#
    App_SubCode_Settings.ebplpfnq.dll!
WebSettings.DataOperation.UpdateXmlByValueDescription(System.Data.DataSet 
ds = {System.Data.DataSet}, string xml = "LocationList.xml") Line 433 + 
0x30 bytes  C#
    App_Web_xvi5k5qk.dll!WebSettings.subLocationList.Update() Line 480 
+ 0x12 bytes    C#
    App_Web_xvi5k5qk.dll!WebSettings.subLocationList.btnSave_Click
(object sender = {Text = "<img src='../Common/images/icon_save.gif' 
border=\"0\">Save "}, System.EventArgs e = {System.EventArgs}) Line 113 + 
0x7 bytes   C#
    [External Code] 

Original issue reported on code.google.com by abdullah...@gmail.com on 5 Nov 2007 at 1:13

GoogleCodeExporter commented 9 years ago
I just want to clarify, the grid itself is simply trying to write some data to 
a 
file, and the file is read only which is why it is not working.  However, the 
part 
that is bothering me is that Elmah is throwing an exception and not able to log 
the 
error.  Above is the details. Thank you

Original comment by abdullah...@gmail.com on 5 Nov 2007 at 1:16

GoogleCodeExporter commented 9 years ago

Original comment by azizatif on 5 Nov 2007 at 1:28

GoogleCodeExporter commented 9 years ago
I think all that is needed is to clean/sanitize the data before logging it, but 
I am 
not sure exactly what function to call to do that.  It's hard to reproduce this 
error unless you are using this specific grid.

Original comment by abdullah...@gmail.com on 5 Nov 2007 at 1:30

GoogleCodeExporter commented 9 years ago
This problem occurs because some detail of the exception cannot be persisted 
since 
the characters in range 0x00 to 0x1F (except 0x09, 0x0A and 0x0D) are not legal 
in 
XML 1.0.

Original comment by azizatif on 5 Nov 2007 at 1:33

GoogleCodeExporter commented 9 years ago
Yes, that's the only way. Actually the XmlWriter.WriteString documentation is 
incorrect:

http://msdn2.microsoft.com/en-us/library/system.xml.xmlwriter.writestring.aspx

It states, "Character values in the range 0x-0x1F (excluding white space 
characters 
0x9, 0xA, and 0xD) are replaced with numeric character entities (� through 
&#0x1F)." However, this does not happen by default. By default, it throws an 
exception. There is a way in .NET 2.0 to disable the character checking by 
setting 
XmlWriterSettings.CheckCharacters to false, but this does not make it legal XML 
1.0. 
As a result sanitization may be the only right approach here.

Original comment by azizatif on 5 Nov 2007 at 1:36

GoogleCodeExporter commented 9 years ago
On second thoughts, it looks like that it may be best to resort to 
XmlWriterSettings.CheckCharacters for now in order to remain compatible with 
.NET 
1.x builds as well as error objects that have already been formatted and 
persisted 
based on the current behavior.

Original comment by azizatif on 5 Nov 2007 at 2:25

GoogleCodeExporter commented 9 years ago
Are you saying Set CheckCharacters to false and check it in to the build?

Original comment by abdullah...@gmail.com on 5 Nov 2007 at 3:40

GoogleCodeExporter commented 9 years ago
> Are you saying Set CheckCharacters to false 
> and check it in to the build?

Yes

Original comment by azizatif on 5 Nov 2007 at 3:45

GoogleCodeExporter commented 9 years ago
Fixed in r237.

Original comment by azizatif on 5 Nov 2007 at 5:12

GoogleCodeExporter commented 9 years ago
You beat me to it, I was just about to email you with the fix.

Original comment by abdullah...@gmail.com on 5 Nov 2007 at 6:06

GoogleCodeExporter commented 9 years ago
I'm running Elmah 1.1.11517.2009 and am receiving this error when pulling up 
elmah.axd.  The error itself is being logged as this error is appearing in 
"ELMAH_Error" (in my SQL DB).

'', hexadecimal value 0x01, is an invalid character. Line 1, position 166.

If I manually hide some of the errors in ELMAH_Error (by changing the 
Application), then elmah.axd works without error.  The stacktrace shows that 
the error is occurring in "Elmah.SqlErrorLog.ErrorsXmlToList()" -- looks like 
on line 61 (sort of hard to tell as I'm reading the XML encoded error directly 
in the DB).

I hid about 20 errors to get elmah.axd to work.  Probably one of those errors 
contains the offending character, but I'm not sure which one.  I've been using 
Elmah for this project for over a year without this problem.  The error was 
logged using Elmah, so I can only speculate a problem persists.  Thanks.

Original comment by ben.am...@gmail.com on 8 Jul 2011 at 3:30

GoogleCodeExporter commented 9 years ago
Following up on my comment, I should say that I just upgraded this project from 
ASP.NET 3.5 to ASP.NET 4.0 about 2 days ago.  Maybe it's related to that?

Original comment by ben.am...@gmail.com on 8 Jul 2011 at 3:31

GoogleCodeExporter commented 9 years ago
Hi there!

Try upgrading to ELMAH v1.2

Cheers,

James

Original comment by jamesdriscoll71 on 8 Jul 2011 at 2:48