[Mono-dev] Issues with XElement.Load() & XmlReader.Create()

Sasha Kogan sashak at mainsoft.com
Mon Apr 28 14:20:03 EDT 2008


To reproduce the bug:

in MonoTests.System.Xml.Linq.XNodeReaderTest.CreateReader1()
(XNodeReaderTest.cs:43) replace  XDocument.Parse(xml) call with
XDocument.Parse(xml, LoadOptions.PreserveWhitespace).

The test will fail with the following stack:

 

System.InvalidOperationException: Node type None is not supported

   at System.Xml.Linq.XNode.ReadFrom(XmlReader r, LoadOptions options)
in
C:\MonoSVN\source\trunk\mcs\class\System.Xml.Linq\System.Xml.Linq\XNode.
cs:line 184

   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader reader,
LoadOptions options) in
C:\MonoSVN\source\trunk\mcs\class\System.Xml.Linq\System.Xml.Linq\XConta
iner.cs:line 196

   at System.Xml.Linq.XElement.LoadCore(XmlReader r, LoadOptions
options) in
C:\MonoSVN\source\trunk\mcs\class\System.Xml.Linq\System.Xml.Linq\XEleme
nt.cs:line 421

   at System.Xml.Linq.XElement.Load(XmlReader reader, LoadOptions
options) in
C:\MonoSVN\source\trunk\mcs\class\System.Xml.Linq\System.Xml.Linq\XEleme
nt.cs:line 395

   at System.Xml.Linq.XNode.ReadFrom(XmlReader r, LoadOptions options)
in
C:\MonoSVN\source\trunk\mcs\class\System.Xml.Linq\System.Xml.Linq\XNode.
cs:line 152

   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader reader,
LoadOptions options) in
C:\MonoSVN\source\trunk\mcs\class\System.Xml.Linq\System.Xml.Linq\XConta
iner.cs:line 196

   at System.Xml.Linq.XDocument.ReadContent(XmlReader reader,
LoadOptions options) in
C:\MonoSVN\source\trunk\mcs\class\System.Xml.Linq\System.Xml.Linq\XDocum
ent.cs:line 150

   at System.Xml.Linq.XDocument.LoadCore(XmlReader reader, LoadOptions
options) in
C:\MonoSVN\source\trunk\mcs\class\System.Xml.Linq\System.Xml.Linq\XDocum
ent.cs:line 135

   at System.Xml.Linq.XDocument.Load(TextReader reader, LoadOptions
options) in
C:\MonoSVN\source\trunk\mcs\class\System.Xml.Linq\System.Xml.Linq\XDocum
ent.cs:line 114

   at System.Xml.Linq.XDocument.Parse(String s, LoadOptions options) in
C:\MonoSVN\source\trunk\mcs\class\System.Xml.Linq\System.Xml.Linq\XDocum
ent.cs:line 173

   ...

 

   The failure is due to "using (XmlReader r = XmlReader.Create (reader,
s))" statement in XElement.cs:394.

   In some cases the instance returned by XmlReader.Create() is 'reader'
itself, thus r.Dispose() at the end of the recursive call invalidates
the reader and the

   attempt to process the next element fails.

   Although MS API states that XmlReader.Create(XmlReader reader,
XmlReaderSettings settings) returns a wrapper that uses the given
instance as an underlying reader, 

   MS implementation returns 'reader' itself in some cases (I think
that's true iff 'settings' is same as 'reader''s settings, but I'm not
100% sure). Mono behavior is different - 

   it returns the instance itself or a wrapper depending on specific
flags in settings.

 

   The bottom line is that we have 2 issues here: 

   

   1) XElement.Load() should not dispose the XmlReader instance upon
completion of recursive calls (if you approve, I'll fix that).

   2) Inconsistent XmlReader.Create() behavior (meaning not consistent
with the API-breaking MS implementation...).

 

Pls your comments & suggestions. 

 

/Sasha

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080428/a19a917e/attachment-0001.html 


More information about the Mono-devel-list mailing list