2017-04-18 07:52:04 +08:00
|
|
|
## XmlSerializer fails while serializing a type that hides an accessible member with an inaccessible one
|
2017-04-06 04:52:19 +08:00
|
|
|
|
|
|
|
### Scope
|
|
|
|
Minor
|
|
|
|
|
|
|
|
### Version Introduced
|
|
|
|
4.5
|
|
|
|
|
|
|
|
### Source Analyzer Status
|
|
|
|
Planned
|
|
|
|
|
|
|
|
### Change Description
|
2017-04-21 02:19:05 +08:00
|
|
|
|
|
|
|
When serializing a derived type, the
|
|
|
|
<xref:System.Xml.Serialization.XmlSerializer?displayProperty=name> can fail if
|
|
|
|
the type contains an inaccessible field or property that hides (via the 'new'
|
|
|
|
keyword) a field or property of the same name that was previously accessible
|
|
|
|
(public, for example) on the base type.
|
2017-04-06 04:52:19 +08:00
|
|
|
|
|
|
|
- [ ] Quirked
|
|
|
|
- [ ] Build-time break
|
|
|
|
|
|
|
|
### Recommended Action
|
|
|
|
|
2017-04-21 02:19:05 +08:00
|
|
|
This problem can be solved by making the new, hiding member accessible to the
|
|
|
|
<xref:System.Xml.Serialization.XmlSerializer?displayProperty=name> (by marking
|
|
|
|
it public, for example).
|
|
|
|
|
|
|
|
Alternatively, the following config setting will revert to 4.0
|
|
|
|
<xref:System.Xml.Serialization.XmlSerializer?displayProperty=name> behavior,
|
|
|
|
which will fix the problem:
|
2017-04-06 04:52:19 +08:00
|
|
|
|
|
|
|
```xml
|
|
|
|
<system.xml.serialization>
|
|
|
|
<xmlSerializer useLegacySerializerGeneration="true" />
|
|
|
|
</system.xml.serialization>
|
|
|
|
```
|
|
|
|
|
|
|
|
### Affected APIs
|
|
|
|
* `M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.Stream,System.Object)`
|
|
|
|
* `M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.TextWriter,System.Object)`
|
|
|
|
* `M:System.Xml.Serialization.XmlSerializer.Serialize(System.Object,System.Xml.Serialization.XmlSerializationWriter)`
|
|
|
|
* `M:System.Xml.Serialization.XmlSerializer.Serialize(System.Xml.XmlWriter,System.Object)`
|
|
|
|
* `M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.Stream,System.Object,System.Xml.Serialization.XmlSerializerNamespaces)`
|
|
|
|
* `M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.TextWriter,System.Object,System.Xml.Serialization.XmlSerializerNamespaces)`
|
|
|
|
* `M:System.Xml.Serialization.XmlSerializer.Serialize(System.Xml.XmlWriter,System.Object,System.Xml.Serialization.XmlSerializerNamespaces)`
|
|
|
|
* `M:System.Xml.Serialization.XmlSerializer.Serialize(System.Xml.XmlWriter,System.Object,System.Xml.Serialization.XmlSerializerNamespaces,System.String)`
|
|
|
|
* `M:System.Xml.Serialization.XmlSerializer.Serialize(System.Xml.XmlWriter,System.Object,System.Xml.Serialization.XmlSerializerNamespaces,System.String,System.String)`
|
|
|
|
|
|
|
|
### Category
|
|
|
|
Serialization
|
|
|
|
|
|
|
|
[More information](http://stackoverflow.com/questions/14689305/serialization-breaks-in-net-4-5)
|
2017-04-18 07:52:04 +08:00
|
|
|
|
|
|
|
<!-- breaking change id: 140 -->
|