dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.27k stars 4.73k forks source link

XmlSerializer Breaks When An Empty Element is in the XML Stream. #67622

Open opcfoundation-org opened 2 years ago

opcfoundation-org commented 2 years ago

Description

Calling Deserialize() on a XML document that has the following in an array of XMLElements: <Value/>

Immediately stops processing (effectively truncating the document).

Works if the following are used: <Value xsi:nil="true" /> or <Value></Value>

The schema for the XML element be de-serialized is here: https://files.opcfoundation.org/schemas/UA/1.05/UANodeSet.xsd The element type is UAVariable.

Seems to be an issue in .NET 5 and .NET 6.

The behaviour where the code works but the document is silently truncated is extremely problematic. If this due to a obscure XML schema rule there should be an exception.

Reproduction Steps

A simple sample project is available.

Expected behavior

Entire document is read when Value is encountered.

Actual behavior

Processing stops when Value is encountered.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

ghost commented 2 years ago

Tagging subscribers to this area: @dotnet/area-system-xml See info in area-owners.md if you want to be subscribed.

Issue Details
### Description Calling Deserialize() on a XML document that has the following in an array of XMLElements: `` Immediately stops processing (effectively truncating the document). Works if the following are used: ` or ` The schema for the XML element be de-serialized is here: https://files.opcfoundation.org/schemas/UA/1.05/UANodeSet.xsd The element type is UAVariable. Seems to be an issue in .NET 5 and .NET 6. The behaviour where the code works but the document is silently truncated is extremely problematic. If this due to a obscure XML schema rule there should be an exception. ### Reproduction Steps A simple sample project is available. ### Expected behavior Entire document is read when is encountered. ### Actual behavior Processing stops when is encountered. ### Regression? _No response_ ### Known Workarounds _No response_ ### Configuration _No response_ ### Other information _No response_
Author: opcfoundation-org
Assignees: -
Labels: `area-System.Xml`, `untriaged`
Milestone: -
opcfoundation-org commented 2 years ago

XmlSerializerBug.zip

StephenMolloy commented 2 years ago

For triage purposes, I can repro this behavior on 4.8, 5.0, 6.0, and 7.0-rc1.