diff --git a/WinRT.Runtime/ComWrappersSupport.net5.cs b/WinRT.Runtime/ComWrappersSupport.net5.cs index f264cdf6c..a250ba418 100644 --- a/WinRT.Runtime/ComWrappersSupport.net5.cs +++ b/WinRT.Runtime/ComWrappersSupport.net5.cs @@ -16,21 +16,31 @@ public static partial class ComWrappersSupport internal static readonly ConditionalWeakTable InspectableInfoTable = new ConditionalWeakTable(); private static ComWrappers _comWrappers; + private static object _comWrappersLock = new object(); private static ComWrappers ComWrappers { get { if (_comWrappers is null) { - _comWrappers = new DefaultComWrappers(); - ComWrappers.RegisterForTrackerSupport(_comWrappers); + lock (_comWrappersLock) + { + if (_comWrappers is null) + { + _comWrappers = new DefaultComWrappers(); + ComWrappers.RegisterForTrackerSupport(_comWrappers); + } + } } return _comWrappers; } set - { - _comWrappers = value; - ComWrappers.RegisterForTrackerSupport(_comWrappers); + { + lock (_comWrappersLock) + { + _comWrappers = value; + ComWrappers.RegisterForTrackerSupport(_comWrappers); + } } }