diff --git a/Orleans.Providers.MongoDB.sln b/Orleans.Providers.MongoDB.sln index cc5f9a6..caf5cd6 100644 --- a/Orleans.Providers.MongoDB.sln +++ b/Orleans.Providers.MongoDB.sln @@ -69,10 +69,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestGrainInterfaces", "libs EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "TestFSharp", "libs\orleans\test\Grains\TestFSharp\TestFSharp.fsproj", "{8A652779-85EF-48E2-A639-1EED3CE2C39C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Orleans.CodeGenerator.MSBuild.Bootstrap", "libs\orleans\src\BootstrapBuild\Orleans.CodeGenerator.MSBuild.Bootstrap\Orleans.CodeGenerator.MSBuild.Bootstrap.csproj", "{7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Orleans.CodeGenerator.MSBuild", "libs\orleans\src\Orleans.CodeGenerator.MSBuild\Orleans.CodeGenerator.MSBuild.csproj", "{A145AFFC-E0CF-4861-AB0C-427C7670FF37}" -EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "TestFSharpInterfaces", "libs\orleans\test\Misc\TestFSharpInterfaces\TestFSharpInterfaces.fsproj", "{A4F61392-36A3-457C-80D0-9CDC48F5922F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestFSharpGrainInterfaces", "libs\orleans\test\Grains\TestFSharpGrainInterfaces\TestFSharpGrainInterfaces.csproj", "{43BD15AA-E53D-4FB5-8E04-765EC86797F5}" @@ -505,38 +501,6 @@ Global {8A652779-85EF-48E2-A639-1EED3CE2C39C}.Release|x64.Build.0 = Release|Any CPU {8A652779-85EF-48E2-A639-1EED3CE2C39C}.Release|x86.ActiveCfg = Release|Any CPU {8A652779-85EF-48E2-A639-1EED3CE2C39C}.Release|x86.Build.0 = Release|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Debug|ARM.ActiveCfg = Debug|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Debug|ARM.Build.0 = Debug|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Debug|x64.ActiveCfg = Debug|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Debug|x64.Build.0 = Debug|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Debug|x86.ActiveCfg = Debug|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Debug|x86.Build.0 = Debug|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Release|Any CPU.Build.0 = Release|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Release|ARM.ActiveCfg = Release|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Release|ARM.Build.0 = Release|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Release|x64.ActiveCfg = Release|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Release|x64.Build.0 = Release|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Release|x86.ActiveCfg = Release|Any CPU - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0}.Release|x86.Build.0 = Release|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Debug|ARM.ActiveCfg = Debug|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Debug|ARM.Build.0 = Debug|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Debug|x64.ActiveCfg = Debug|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Debug|x64.Build.0 = Debug|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Debug|x86.ActiveCfg = Debug|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Debug|x86.Build.0 = Debug|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Release|Any CPU.Build.0 = Release|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Release|ARM.ActiveCfg = Release|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Release|ARM.Build.0 = Release|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Release|x64.ActiveCfg = Release|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Release|x64.Build.0 = Release|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Release|x86.ActiveCfg = Release|Any CPU - {A145AFFC-E0CF-4861-AB0C-427C7670FF37}.Release|x86.Build.0 = Release|Any CPU {A4F61392-36A3-457C-80D0-9CDC48F5922F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A4F61392-36A3-457C-80D0-9CDC48F5922F}.Debug|Any CPU.Build.0 = Debug|Any CPU {A4F61392-36A3-457C-80D0-9CDC48F5922F}.Debug|ARM.ActiveCfg = Debug|Any CPU @@ -726,8 +690,6 @@ Global {0ECCC344-21E8-4AD7-9CB9-933054200000} = {00BCCB49-80FC-48E4-8A2B-89E0F6313457} {CC76035A-056B-43F3-8FFB-92DE66A19305} = {00BCCB49-80FC-48E4-8A2B-89E0F6313457} {8A652779-85EF-48E2-A639-1EED3CE2C39C} = {00BCCB49-80FC-48E4-8A2B-89E0F6313457} - {7735FCC6-4D1F-4FCA-8D8F-44515EF558C0} = {00BCCB49-80FC-48E4-8A2B-89E0F6313457} - {A145AFFC-E0CF-4861-AB0C-427C7670FF37} = {00BCCB49-80FC-48E4-8A2B-89E0F6313457} {A4F61392-36A3-457C-80D0-9CDC48F5922F} = {00BCCB49-80FC-48E4-8A2B-89E0F6313457} {43BD15AA-E53D-4FB5-8E04-765EC86797F5} = {00BCCB49-80FC-48E4-8A2B-89E0F6313457} {9BCF7A12-6A5B-43FF-828A-A804F9B9DBB4} = {00BCCB49-80FC-48E4-8A2B-89E0F6313457} diff --git a/Orleans.Providers.MongoDB/Orleans.Providers.MongoDB.csproj b/Orleans.Providers.MongoDB/Orleans.Providers.MongoDB.csproj index 1815fd9..3dfd35b 100644 --- a/Orleans.Providers.MongoDB/Orleans.Providers.MongoDB.csproj +++ b/Orleans.Providers.MongoDB/Orleans.Providers.MongoDB.csproj @@ -15,7 +15,7 @@ Orleans OrleansProviders MongoDB snupkg net8.0 - 8.0.3 + 8.0.4 diff --git a/Orleans.Providers.MongoDB/StorageProviders/Serializers/JsonGrainStateSerializer.cs b/Orleans.Providers.MongoDB/StorageProviders/Serializers/JsonGrainStateSerializer.cs index b281d6e..a35ff29 100644 --- a/Orleans.Providers.MongoDB/StorageProviders/Serializers/JsonGrainStateSerializer.cs +++ b/Orleans.Providers.MongoDB/StorageProviders/Serializers/JsonGrainStateSerializer.cs @@ -10,24 +10,26 @@ namespace Orleans.Providers.MongoDB.StorageProviders.Serializers { public class JsonGrainStateSerializer : IGrainStateSerializer { - private readonly JsonSerializer serializer; + private readonly JsonSerializerSettings _jsonSettings; public JsonGrainStateSerializer(IOptions options, IServiceProvider serviceProvider) { - var jsonSettings = OrleansJsonSerializerSettings.GetDefaultSerializerSettings(serviceProvider); - options.Value.ConfigureJsonSerializerSettings(jsonSettings); - serializer = JsonSerializer.CreateDefault(jsonSettings); + _jsonSettings = OrleansJsonSerializerSettings.GetDefaultSerializerSettings(serviceProvider); + options.Value.ConfigureJsonSerializerSettings(_jsonSettings); } public T Deserialize(BsonValue value) { using var jsonReader = new JTokenReader(value.ToJToken()); - return serializer.Deserialize(jsonReader); + // Creating a new serializer instance to avoid thread-safety issue: https://github.com/JamesNK/Newtonsoft.Json/issues/1452 + var jsonSerializer = JsonSerializer.CreateDefault(_jsonSettings); + return jsonSerializer.Deserialize(jsonReader); } public BsonValue Serialize(T state) { - return JObject.FromObject(state, serializer).ToBson(); + var jsonSerializer = JsonSerializer.CreateDefault(_jsonSettings); + return JObject.FromObject(state, jsonSerializer).ToBson(); } } }