From 900c83f437c36f3b3d5385f64f26744884d6b2a3 Mon Sep 17 00:00:00 2001 From: Steve Molloy Date: Thu, 22 Aug 2024 16:01:16 -0700 Subject: [PATCH] [release/8.0-staging] Sys.RT.Caching.MemoryCache - Remove unhandled exception handler (#106221) * Remove UnhandledException handler from MemoryCache to avoid deadlock. * Update Sys.RT.Caching csproj for servicing build. --- .../src/System.Runtime.Caching.csproj | 2 ++ .../src/System/Runtime/Caching/MemoryCache.cs | 18 ------------------ 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Runtime.Caching/src/System.Runtime.Caching.csproj b/src/libraries/System.Runtime.Caching/src/System.Runtime.Caching.csproj index b3d85127f0212..241cbbffb2136 100644 --- a/src/libraries/System.Runtime.Caching/src/System.Runtime.Caching.csproj +++ b/src/libraries/System.Runtime.Caching/src/System.Runtime.Caching.csproj @@ -3,6 +3,8 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum);netstandard2.0 true true + true + 1 true true true diff --git a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryCache.cs b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryCache.cs index e740eed69ed51..38514ce521abc 100644 --- a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryCache.cs +++ b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryCache.cs @@ -39,7 +39,6 @@ public class MemoryCache : ObjectCache, IEnumerable, IDisposable private bool _useMemoryCacheManager = true; private bool _throwOnDisposed; private EventHandler _onAppDomainUnload; - private UnhandledExceptionEventHandler _onUnhandledException; #if NETCOREAPP [UnsupportedOSPlatformGuard("browser")] private static bool _countersSupported => !OperatingSystem.IsBrowser(); @@ -219,9 +218,6 @@ private void InitDisposableMembers(NameValueCollection config) EventHandler onAppDomainUnload = new EventHandler(OnAppDomainUnload); appDomain.DomainUnload += onAppDomainUnload; _onAppDomainUnload = onAppDomainUnload; - UnhandledExceptionEventHandler onUnhandledException = new UnhandledExceptionEventHandler(OnUnhandledException); - appDomain.UnhandledException += onUnhandledException; - _onUnhandledException = onUnhandledException; dispose = false; } finally @@ -238,16 +234,6 @@ private void OnAppDomainUnload(object unusedObject, EventArgs unusedEventArgs) Dispose(); } - private void OnUnhandledException(object sender, UnhandledExceptionEventArgs eventArgs) - { - // if the CLR is terminating, dispose the cache. - // This will dispose the perf counters - if (eventArgs.IsTerminating) - { - Dispose(); - } - } - private static void ValidatePolicy(CacheItemPolicy policy) { if (policy.AbsoluteExpiration != ObjectCache.InfiniteAbsoluteExpiration @@ -500,10 +486,6 @@ private void DisposeSafeCritical() { appDomain.DomainUnload -= _onAppDomainUnload; } - if (_onUnhandledException != null) - { - appDomain.UnhandledException -= _onUnhandledException; - } } private object GetInternal(string key, string regionName)