diff --git a/Flow.Launcher/Helper/ErrorReporting.cs b/Flow.Launcher/Helper/ErrorReporting.cs index 797f31482ce..e2431fd4f05 100644 --- a/Flow.Launcher/Helper/ErrorReporting.cs +++ b/Flow.Launcher/Helper/ErrorReporting.cs @@ -25,6 +25,12 @@ private static void Report(Exception e, bool silent = false, [CallerMemberName] // 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 5dd57f9bbcd..0cc7747ad7c 100644 --- a/Flow.Launcher/Helper/ExceptionHelper.cs +++ b/Flow.Launcher/Helper/ExceptionHelper.cs @@ -39,4 +39,23 @@ internal static bool IsRecoverableDwmCompositionException(Exception exception) 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); + } }