Skip to content

Commit 38865d0

Browse files
authored
[Blazor] Fix race condition when caching for a type of QueryParameterValueSupplier (#40636)
* Use a concurrent dictionary to avoid race conditions.
1 parent 7915086 commit 38865d0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Components/Components/src/Routing/QueryParameterValueSupplier.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Buffers;
5+
using System.Collections.Concurrent;
56
using System.Diagnostics.CodeAnalysis;
67
using System.Reflection;
78
using Microsoft.AspNetCore.Components.Reflection;
@@ -15,7 +16,7 @@ internal sealed class QueryParameterValueSupplier
1516
{
1617
public static void ClearCache() => _cacheByType.Clear();
1718

18-
private static readonly Dictionary<Type, QueryParameterValueSupplier?> _cacheByType = new();
19+
private static readonly ConcurrentDictionary<Type, QueryParameterValueSupplier?> _cacheByType = new();
1920

2021
// These two arrays contain the same number of entries, and their corresponding positions refer to each other.
2122
// Holding the info like this means we can use Array.BinarySearch with less custom implementation.

0 commit comments

Comments
 (0)