Fix CheckSpecified setter for field-backed members in ReflectionXmlSerializationReader#126035
Open
haltandcatchwater wants to merge 2 commits intodotnet:mainfrom
Open
Fix CheckSpecified setter for field-backed members in ReflectionXmlSerializationReader#126035haltandcatchwater wants to merge 2 commits intodotnet:mainfrom
haltandcatchwater wants to merge 2 commits intodotnet:mainfrom
Conversation
…herited ShouldSerialize methods ReflectionXmlSerializationWriter used BindingFlags.DeclaredOnly when looking up ShouldSerialize methods at two call sites, which prevented finding methods declared on base classes. This caused a NullReferenceException when serializing derived types whose base class defines the ShouldSerialize method. The MemberMapping already stores the correctly resolved MethodInfo (CheckShouldPersistMethodInfo), which is resolved without DeclaredOnly during import and used by the IL-gen path. Use it directly in the reflection path to match the IL-gen behavior. Fix dotnet#120561
…ld-backed members
ReflectionXmlSerializationReader used GetMethod("set_X") to set
XxxSpecified members during deserialization. This only finds property
setters, silently skipping field-backed Specified members. The rest of
the reflection reader uses GetSetMemberValueDelegate which handles
both fields and properties and caches the delegate.
Replace the GetMethod call with GetSetMemberValueDelegate to align
with the existing pattern and fix deserialization of types with
field-backed Specified members.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ReflectionXmlSerializationReaderusedGetMethod("set_X")to setXxxSpecifiedmembers during deserialization. This only finds property setters — for field-backedSpecifiedmembers,GetMethodreturns null and the setter is silently skipped, leaving theSpecifiedflag asfalseeven when the element is present in the XML.The rest of the reflection reader already uses
GetSetMemberValueDelegate(which handles both fields and properties and caches the delegate). The ILGen reader handles both viaILGenSet. This was the only call site using the rawGetMethod("set_X")pattern.Related to #125859 (same class of reflection-path drift from the ILGen path).
Changes
GetMethod("set_X")+?.InvokewithGetSetMemberValueDelegate, resolving once and cachingTypeWithFieldBackedSpecifiedMemberwith apublic bool FooSpecifiedfieldFooSpecifiedis set totrueafter round-trip deserialization