You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
XmlReader ReadElementContentAsString Hangs if End of Document Tag Reached in Stream #1029
Given the following XML sent over a network stream: <?xml version="1.0" encoding="utf-16"?><DeviceCommand>PlayTone</DeviceCommand>
Which is generated by the XmlWriter command:
var writer = XmlWriter.Create(namedPipeClientStream)
writer.WriteElementString("DeviceCommand", "PlayTone")
writer.Flush()
This reader command will cause an XML reader on the server to hang until the network stream is closed:
var reader = XmlReader.Create(namedPipeServerStream)
reader.MoveToContent()
var txt = reader.ReadElementContentAsString()
The command fails even though the entire element was sent. This alternative command works as expected:
reader.MoveToContent()
reader.Read()
var txt = reader.Value;
However, if the stream is closed, then the XmlReader is able to read the node without issue and the call to ReadElementContentAsString works as expected.
It looks like XmlReader is waiting until it gets the node after the EndElement before it returns the string, but it doesn't properly recognize the end of the root node. This appears to be undocumented behavior.
@iUnknwn thank you for reporting the issue, this issue needs some detailed investigations which cannot be done within .Net 5.
It would be great if you would be interested in doing the investigation/fixes.
I could probably write up an MSUnit/xUnit test to test for this behavior, if you're looking for something basic to demo the problem.
That would be very helpful for whoever would investigate it
If you're looking for a patch/PR to fix the issue, that might be a bit trickier.
Sure it is not easy, and it is optional/voluntary. If you are willing to contribute for test repro, finding the root cause, propose a fix or raise a PR etc., whichever level it was that would be very helpful. Thanks again!
@buyaa-n Sorry this took so long, but I have a repo setup with test cases for this issue. It shows the issue only happens on open streams, and it specifically occurs on single-element html items.
For now I believe you should be able to use ReadContentAsString which ReadElementContentAsString calls internally except ReadElementContentAsString also tries to move to the next element.
Activity
buyaa-n commentedon Jun 29, 2020
@iUnknwn thank you for reporting the issue, this issue needs some detailed investigations which cannot be done within .Net 5.
It would be great if you would be interested in doing the investigation/fixes.
iUnknwn commentedon Jun 30, 2020
@buyaa-n I'd be potentially interested, what are you asking for?
I could probably write up an MSUnit/xUnit test to test for this behavior, if you're looking for something basic to demo the problem.
If you're looking for a patch/PR to fix the issue, that might be a bit trickier.
buyaa-n commentedon Jun 30, 2020
That would be very helpful for whoever would investigate it
Sure it is not easy, and it is optional/voluntary. If you are willing to contribute for test repro, finding the root cause, propose a fix or raise a PR etc., whichever level it was that would be very helpful. Thanks again!
iUnknwn commentedon Aug 6, 2020
@buyaa-n Sorry this took so long, but I have a repo setup with test cases for this issue. It shows the issue only happens on open streams, and it specifically occurs on single-element html items.
https://github.com/iUnknwn/XmlReaderBugDemo
Please let me know if you need more info.
krwq commentedon Jul 15, 2021
For now I believe you should be able to use
ReadContentAsStringwhichReadElementContentAsStringcalls internally exceptReadElementContentAsStringalso tries to move to the next element.I think the fix for this should be somewhere here
runtime/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlReader.cs
Line 1607 in 57bfe47
but this will likely require more investigation as there are more than one XmlReader implementation in the framework.
I'm moved this to 7.0 for now since we do not plan to do this investigation in 6.0