Repository navigation
XmlTextReader.Read throws ArgumentNullException #1409
Description
Activity
Questionable choice of exception for XML to throw on malformed XML.
This type is actually internal to DCS.
We should throw a different exception other than ArgumentNullException. However, due to the issue is not reported by real world scenario, this is lower priority issue.
- addeduntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
on Jan 7, 2020 - added and removeduntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
on Jan 7, 2020 - addeduntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
on Feb 23, 2020 - removeduntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
on Feb 28, 2020 Simple fix, low priority scenario.
@imcarolwang Could you add this as something for your team to try fixing.@imcarolwang is this still on your radar?
7 remaining items
- changed the title
[-]DataContractSerializer.ReadObject throws ArgumentNullException[/-][+]XmlTextReader.Read throws ArgumentNullException[/+]on Oct 9, 2021 - removeduntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
on Oct 11, 2021 @Metalnem do you feel like sending PR with a tiny test? I can help with that if needed
- added a commit that references this issue
on Dec 9, 2021 @imcarolwang - If this still repros,
System.Xml.XmlUTF8TextReader.VerifyNCNameshould be null-checking before going forward and throwing an XmlException instead.@StephenMolloy, I haven't been able to reproduce this issue, on my repro environment, the stack trace seems missing some details than reported in issue, the exception is
System.Runtime.Serialization.SerializationException, notArgumentNullException, like I pasted before even on net6.0, do I miss something in repro the bug? I tried to run the code on both Windows and Ubuntu OS, I am not sure if it has difference than on Mac OS ...Update: I just realized I made a silly mistake when reproducing the issue—it was because I used mismatched namespace in the demo code. The issue is still reproducible on both .NET Framework and .NET platforms.
Looks like this is still reproducible. But I will say this... it also reproduces on 4.8. And of course the Xml being processed here is malformed. I misspoke earlier about VerifyNCName. It's doing the same thing it has always done since 4.8. I suppose the question is whether a frame further up the stack should be wrapping the
ArgumentNullExceptionin something higher-level likeSerializationException.- addedin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
on Aug 11, 2025 I think I was working with the wrong mental context in my last comment when I said I misspoke about VerifyNCName. I actually believe that is where the fix should probably be. I don't know why my last comment made it sound like "nothing has changed there, so that can't be the cause" when the sentence right before literally states that this odd exception type has been the case going all the way back to .Net 4.8.
The proposed fix works for the repro, but it is probably at the wrong layer. Catching ArgumentException around the entire XmlObjectSerializer.ReadObjectHandleExceptions scope changes behavior for more than this XML reader bug, including DataContractJsonSerializer and user/deserialization code that throws ArgumentException. I’d prefer fixing the narrow source in System.Private.DataContractSerialization\src\System\Xml\XmlUTF8TextReader.cs (VerifyNCName) so the malformed XML becomes an XmlException, which the existing DCS wrapper already converts to SerializationException.
- added a commit that references this issue
on Jun 2, 2026 - locked and limited conversation to collaborators
on Jul 3, 2026 - added a commit that references this issue
on Jul 15, 2026
DataContractSerializer.ReadObject sometimes throws ArgumentNullException. Here's the full program that reproduces this:
The stack trace:
The environment:
Found via SharpFuzz.