dotnet / dotnet/wcf

XmlSerializer don't load after first missing property

Open
#5,762 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1.8k
Forks
576
Avg merge
6d 9h
Merged PRs (30d)
2

Description

**Describe the bug**

When an object from a WCF API is deserialized, if that API has a new property that does NOT exist in the model, all data in the document after that property is not loaded, even if it exists in the model.

If a property has the [XmlAnyElement] attribute, all unread values ​​are saved there (even though the model DOES have those attributes).

All properties are loaded correctly even though the XML does not include the property that triggers the error.

An important detail is that if a base object has the [XmlAnyElement] property, all classes that inherit from it are NOT deserialized; all their values ​​are hijacked by the attribute, even if an Order value is set to very high.

Using DataContract is not a viable option, as svcutil generates numerous errors when using that serializer (all are of this type).

```
Warning: The optional WSDL extension element "body" from the namespace "http://schemas.xmlsoap.org/wsdl/soap12/" was not handled.
XPath: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='NetHttpBinding_IWebServiceHttp']/wsdl:operation[@name='TaskNewChange']/wsdl:output
```

**To Reproduce**
Steps to reproduce the behavior:

1. Create an API with the netTcpBinding protocol in .NET 4.5 with a method that returns an object with multiple properties.

2. In a .NET Maui version 9 project, add the reference to the WCF service.

3. Modify the API of the first project to add a new, optional, nullable property (ordered among the other properties, so that the new property isn't last).

4. (WITHOUT updating the references) When calling the API from the Maui project, when loading the data, ALL the properties that were after the new property are NOT loaded.

**Expected behavior**

New node values ​​from the XML that do not exist in the model should be ignored or stored in the property with the [XmlAnyElement] attribute and respecting inheritance. Since a Base object hijacks values ​​and should not

**Screenshots**

Cut of the XML response.
```










Example value
Winter
Planning






c53f3a22-c9b0-4b90-b62c-fc3a0bcf9875
69528d60-ca21-4412-a2b2-d087337fbf60
14687ec7-b19e-499b-809f-0a6c8abcf7c2

```
Look que end node (Items has values inside)
Look **PreparationInstructions** it's the new property not in model
Look **Remarks** and **Season** has value
Look **TrialVarieties** has items inside
Look **State** Planning it's not load (this value it's the default)

Image

Adding to the model a property with XmlAnyElement all nodes after the missing it's added to XmlAnyElementProperty and not loaded

Image

**Additional context**

It is important that the data loading is robust, since an API can be updated with optional parameters and that should not break the loading.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.