diff --git a/src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs b/src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs index 3e754b5bbcc2..eb83f661e237 100644 --- a/src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs +++ b/src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs @@ -332,19 +332,17 @@ public JsonPropertyInfo GetProperty(ReadOnlySpan propertyName, ref ReadSta // No cached item was found. Try the main list which has all of the properties. string stringPropertyName = JsonHelpers.Utf8GetString(propertyName); - PropertyCache.TryGetValue(stringPropertyName, out JsonPropertyInfo info); + if (!PropertyCache.TryGetValue(stringPropertyName, out JsonPropertyInfo info)) + { + info = JsonPropertyInfo.s_missingProperty; + } // Three code paths to get here: - // 1) info == null. Property not found. + // 1) info == s_missingProperty. Property not found. // 2) key == info.PropertyNameKey. Exact match found. // 3) key != info.PropertyNameKey. Match found due to case insensitivity. Debug.Assert(info == null || key == info.PropertyNameKey || Options.PropertyNameCaseInsensitive); - if (info == null) - { - info = JsonPropertyInfo.s_missingProperty; - } - // Check if we should add this to the cache. // Only cache up to a threshold length and then just use the dictionary when an item is not found in the cache. int cacheCount;