diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj
index d88d2be69fefd..3ee7607c9b11b 100644
--- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj
+++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj
@@ -9,7 +9,8 @@
enable
true
true
- 3
+ true
+ 4
Provides high-performance and low-allocating types that serialize objects to JavaScript Object Notation (JSON) text and deserialize JSON text to objects, with UTF-8 support built-in. Also provides types to read and write JSON text encoded as UTF-8, and to create an in-memory document object model (DOM), that is read-only, for random access of the JSON elements within a structured view of the data.
Commonly Used Types:
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs
index 77b5d7071f712..2563794dcc55c 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs
@@ -10,6 +10,7 @@
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Converters;
using System.Text.Json.Serialization.Metadata;
+using System.Threading;
namespace System.Text.Json
{
@@ -30,10 +31,10 @@ public sealed partial class JsonSerializerOptions
[RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)]
private void RootBuiltInConverters()
{
- if (s_defaultSimpleConverters is null)
+ if (Volatile.Read(ref s_defaultFactoryConverters) is null)
{
s_defaultSimpleConverters = GetDefaultSimpleConverters();
- s_defaultFactoryConverters = new JsonConverter[]
+ Volatile.Write(ref s_defaultFactoryConverters, new JsonConverter[]
{
// Check for disallowed types.
new UnsupportedTypeConverterFactory(),
@@ -48,7 +49,7 @@ private void RootBuiltInConverters()
new IEnumerableConverterFactory(),
// Object should always be last since it converts any type.
new ObjectConverterFactory()
- };
+ });
}
}