Hi @AlexTeixeira,
first I want to thank you for this great library and I hope you are doing well.
Today I had a lot of invalid operation exceptions with the following message and stack trace:
Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
at System.Collections.Generic.HashSet`1.Contains(T item)
at Askmethat.Aspnet.JsonLocalizer.Localizer.JsonStringLocalizerBase.AddMissingCultureToSupportedCulture(CultureInfo cultureInfo)
at Askmethat.Aspnet.JsonLocalizer.Localizer.JsonStringLocalizerBase.InitJsonStringLocalizer()
at ResolveService(ILEmitResolverBuilderRuntimeContext , ServiceProviderEngineScope )
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
at lambda_method(Closure , IServiceProvider , Object[] )
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Extensions.Web.Api.Middleware.ApiLoggingMiddleware.InvokeAsync(HttpContext httpContext)
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
The application is an ASP.NET CORE 3.1 app with the library version 2.2.0-preview3. Although the library seems to be outdated, the part of the code where the issue arises is identical.
I think the issue occurs due to a change of dotnet/runtime#26868, where Hashsets are never thread safe for a write and any other operation (read or write) since release of .NET CORE 2.1.0.
From this I assume the IOptions<JsonLocalizationOptions> _localizationOptions is beeing modified concurrently in Localizer/JsonStringLocalizerBase.cs#L100-L106 and therefore the InvalidOperationException is thrown.
Kind regards, Greg
Hi @AlexTeixeira,
first I want to thank you for this great library and I hope you are doing well.
Today I had a lot of invalid operation exceptions with the following message and stack trace:
Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
The application is an ASP.NET CORE 3.1 app with the library version 2.2.0-preview3. Although the library seems to be outdated, the part of the code where the issue arises is identical.
I think the issue occurs due to a change of dotnet/runtime#26868, where Hashsets are never thread safe for a write and any other operation (read or write) since release of .NET CORE 2.1.0.
From this I assume the
IOptions<JsonLocalizationOptions> _localizationOptionsis beeing modified concurrently in Localizer/JsonStringLocalizerBase.cs#L100-L106 and therefore the InvalidOperationException is thrown.Kind regards, Greg