diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs index c6485d6863b18a..724987b6db2881 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs @@ -102,6 +102,25 @@ public Func? CreateObject private protected abstract void SetCreateObject(Delegate? createObject); private protected Func? _createObject; + private protected void AfterCreateObject() + { + // Clear any data related to the previously specified ctor + ConstructorAttributeProviderFactory = null; + ConstructorAttributeProvider = null; + + if (CreateObjectWithArgs is not null) + { + _parameterInfoValuesIndex = null; + CreateObjectWithArgs = null; + ParameterCount = 0; + + foreach (JsonPropertyInfo propertyInfo in PropertyList) + { + propertyInfo.AssociatedParameter = null; + } + } + } + internal Func? CreateObjectForExtensionDataProperty { get; set; } /// diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfoOfT.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfoOfT.cs index 7a00b678d59899..c19c0f73bdd722 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfoOfT.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfoOfT.cs @@ -98,21 +98,7 @@ private protected override void SetCreateObject(Delegate? createObject) _createObject = untypedCreateObject; _typedCreateObject = typedCreateObject; - // Clear any data related to the previously specified ctor - ConstructorAttributeProviderFactory = null; - ConstructorAttributeProvider = null; - - if (CreateObjectWithArgs is not null) - { - _parameterInfoValuesIndex = null; - CreateObjectWithArgs = null; - ParameterCount = 0; - - foreach (JsonPropertyInfo propertyInfo in PropertyList) - { - propertyInfo.AssociatedParameter = null; - } - } + AfterCreateObject(); } ///