From 41d5e0a27a20eec110beca672c4217bbcbb83feb Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sat, 28 Feb 2026 14:39:15 +0800 Subject: [PATCH] Revert "Fix: Silently handle InvalidCastException from WPF system resource invalidation on Windows theme change" This reverts commit 372f142b49e00e2e5210eed3e401137c5c430a67. --- Flow.Launcher/Helper/ErrorReporting.cs | 6 ------ Flow.Launcher/Helper/ExceptionHelper.cs | 19 ------------------- 2 files changed, 25 deletions(-) diff --git a/Flow.Launcher/Helper/ErrorReporting.cs b/Flow.Launcher/Helper/ErrorReporting.cs index e2431fd4f..797f31482 100644 --- a/Flow.Launcher/Helper/ErrorReporting.cs +++ b/Flow.Launcher/Helper/ErrorReporting.cs @@ -25,12 +25,6 @@ public static class ErrorReporting // This change modifies the behavior to log the exception instead of showing the "Error report UI". if (ExceptionHelper.IsRecoverableDwmCompositionException(e)) return; - // Workaround for a WPF issue where changing the Windows theme or accent color triggers - // SystemResources.InvalidateTreeResources, which tries to clone Color values stored in styles - // and fails with an InvalidCastException. This is a benign framework-level exception that - // does not affect Flow Launcher functionality, so we log it silently instead of showing the error dialog. - if (ExceptionHelper.IsRecoverableSystemResourceException(e)) return; - var reportWindow = new ReportWindow(e); reportWindow.Show(); } diff --git a/Flow.Launcher/Helper/ExceptionHelper.cs b/Flow.Launcher/Helper/ExceptionHelper.cs index 0cc7747ad..5dd57f9bb 100644 --- a/Flow.Launcher/Helper/ExceptionHelper.cs +++ b/Flow.Launcher/Helper/ExceptionHelper.cs @@ -39,23 +39,4 @@ internal static class ExceptionHelper return !string.IsNullOrEmpty(stackTrace) && stackTrace.Contains("DwmCompositionChanged", StringComparison.OrdinalIgnoreCase); } - - /// - /// Returns true if the exception is a recoverable WPF system resource invalidation exception - /// that occurs when Windows changes its theme or accent colors. This is a known WPF issue where - /// Color values stored in styles are incorrectly cloned during resource tree invalidation. - /// - internal static bool IsRecoverableSystemResourceException(Exception exception) - { - if (exception is not InvalidCastException) - { - return false; - } - - // Check for the specific Color-to-Expression cast failure originating from WPF's - // SystemResources.InvalidateTreeResources, triggered by Windows theme/accent color changes. - var stackTrace = exception.StackTrace; - return !string.IsNullOrEmpty(stackTrace) && - stackTrace.Contains("System.Windows.SystemResources.InvalidateTreeResources", StringComparison.Ordinal); - } }