diff --git a/src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs b/src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs index 6f91cb21f038cd..e3cd7394046c0b 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs +++ b/src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs @@ -145,6 +145,8 @@ public void Dispose() { IsDisposed = true; + CacheEntryHelper.ExitScope(this, _previous); + // Don't commit or propagate options if the CacheEntry Value was never set. // We assume an exception occurred causing the caller to not set the Value successfully, // so don't use this entry. @@ -158,7 +160,6 @@ public void Dispose() } } - CacheEntryHelper.ExitScope(this, _previous); _previous = null; // we don't want to root unnecessary objects } }