private static X509Store EnsureStoreOpened(ref X509Store storeField, StoreLocation storeLocation)
{
X509Store store = Volatile.Read(ref storeField);
if (store == null)
{
lock (s_lockObject)
{
store = Volatile.Read(ref storeField);
if (store == null)
{
try
{
store = new X509Store(StoreName.My, storeLocation);
store.Open(OpenFlags.ReadOnly);
Volatile.Write(ref storeField, store);
if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"storeLocation: {storeLocation} returned store {store}");
}
catch (CryptographicException e)
{
NetEventSource.Fail(null, $"Failed to open cert store, location: {storeLocation} exception {e}");
throw;
}
}
}
}
return store;
}