Skip to content

Commit fd3e8f2

Browse files
mayukijaviercn
authored andcommitted
[Blazor] Fix race condition when caching for a type of QueryParameterValueSupplier (#40636)
* Use a concurrent dictionary to avoid race conditions.
1 parent 7c2000d commit fd3e8f2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55
using System.Buffers;
6-
using System.Collections.Generic;
6+
using System.Collections.Concurrent;
77
using System.Diagnostics.CodeAnalysis;
88
using System.Reflection;
99
using Microsoft.AspNetCore.Components.Reflection;
@@ -17,7 +17,7 @@ internal sealed class QueryParameterValueSupplier
1717
{
1818
public static void ClearCache() => _cacheByType.Clear();
1919

20-
private static readonly Dictionary<Type, QueryParameterValueSupplier?> _cacheByType = new();
20+
private static readonly ConcurrentDictionary<Type, QueryParameterValueSupplier?> _cacheByType = new();
2121

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

0 commit comments

Comments
 (0)