Closed sloncho closed 5 months ago
Do you have any update for this serious bug? I suppose GetElement should apply the same check on nil attribute as done for SetElement.
internal void SetElement(XName name, object value, bool addToExisting, XmlSchemaDatatype datatype, Type elementBaseType)
{
XElement untyped = GetUntyped();
CheckXsiNil(untyped);
...
private void CheckXsiNil(XElement parentElement)
{
XAttribute xAttribute = parentElement.Attributes(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance")).FirstOrDefault();
if (xAttribute != null && xAttribute.Value == "true")
{
xAttribute.Remove();
}
}
@mamift Do you have some plan for this bug fix?
It appears that the generated code for nullable property getter only inspects if the element exists. It fails when the element exists with attribute "xsi:nil"=true.
Example: xsd:
<xsd:element name="createDate" type="xsd:dateTime" minOccurs="0" nillable="true" />
Incoming xml:
When accessing the generated
createDate
property, it throws, as it finds the element, and tries to parse the empty value to DateTime.As XDocument/XElement are not schema-aware, I'm not even sure which approach for solving this will be more appropriate - inspecting for the nil=true, or using the XElement.IsEmpty to detect the null value.