Skip to content

Suppress spurious error dialog on Windows theme/accent color change#4301

Closed
Copilot wants to merge 2 commits into
devfrom
copilot/fix-cast-exception-bug
Closed

Suppress spurious error dialog on Windows theme/accent color change#4301
Copilot wants to merge 2 commits into
devfrom
copilot/fix-cast-exception-bug

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

Switching Windows themes triggers WPF's SystemResources.InvalidateTreeResources, which walks the visual tree cloning style values. When Color structs are encountered where WPF expects a Freezable/Expression, it throws System.InvalidCastException — a framework-level bug the app can't prevent, but was surfacing as a user-visible error dialog.

Changes

  • ExceptionHelper.cs — Added IsRecoverableSystemResourceException(): detects InvalidCastException originating from System.Windows.SystemResources.InvalidateTreeResources in the stack trace, mirroring the existing IsRecoverableDwmCompositionException() pattern.

  • ErrorReporting.cs — In Report(), early-return (log only, no dialog) when IsRecoverableSystemResourceException() is true.

// ExceptionHelper.cs
internal static bool IsRecoverableSystemResourceException(Exception exception)
{
    if (exception is not InvalidCastException) return false;

    var stackTrace = exception.StackTrace;
    return !string.IsNullOrEmpty(stackTrace) &&
           stackTrace.Contains("System.Windows.SystemResources.InvalidateTreeResources", StringComparison.Ordinal);
}

The exception is still logged at Fatal level; only the error report window is suppressed.

Original prompt

This section details on the original issue you should resolve

<issue_title>BUG: Unable to cast object of type 'System.Windows.Media.Color' to type 'System.Windows.Expression'</issue_title>
<issue_description>### Checks

  • I have checked that this issue has not already been reported.

  • I am using the latest version of Flow Launcher.

  • I am using the prerelease version of Flow Launcher.

Problem Description

Flow Launcher version: 2.1.0
OS Version: 26200.7922
IntPtr Length: 8
x64: True

Python Path: 
Node Path: 

Date: 02/27/2026 09:26:31
Exception:
System.InvalidCastException: Unable to cast object of type 'System.Windows.Media.Color' to type 'System.Windows.Expression'.
   at System.Windows.Freezable.CloneCoreCommon(Freezable sourceFreezable, Boolean useCurrentValue, Boolean cloneFrozenValues)
   at System.Windows.Freezable.Clone()
   at System.Windows.StyleHelper.GetInstanceValue(UncommonField`1 dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, Int32 childIndex, DependencyProperty dp, Int32 i, EffectiveValueEntry& entry)
   at System.Windows.StyleHelper.GetChildValueHelper(UncommonField`1 dataField, ItemStructList`1& valueLookupList, DependencyProperty dp, DependencyObject container, FrameworkObject child, Int32 childIndex, Boolean styleLookup, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
   at System.Windows.StyleHelper.GetChildValue(UncommonField`1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
   at System.Windows.StyleHelper.GetValueFromStyleOrTemplate(FrameworkObject fo, DependencyProperty dp, EffectiveValueEntry& entry)
   at System.Windows.FrameworkElement.GetRawValue(DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry& entry)
   at System.Windows.FrameworkElement.EvaluateBaseValueCore(DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry& newEntry)
   at System.Windows.DependencyObject.EvaluateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry, OperationType operationType)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   at System.Windows.StyleHelper.InvalidateResourceDependents(DependencyObject container, ResourcesChangeInfo info, FrugalStructList`1& resourceDependents, Boolean invalidateVisualTreeToo)
   at System.Windows.TreeWalkHelper.InvalidateStyleAndReferences(DependencyObject d, ResourcesChangeInfo info, Boolean containsTypeOfKey)
   at System.Windows.TreeWalkHelper.OnResourcesChanged(DependencyObject d, ResourcesChangeInfo info, Boolean raiseResourceChangedEvent)
   at System.Windows.TreeWalkHelper.OnResourcesChangedCallback(DependencyObject d, ResourcesChangeInfo info, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator ...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes Flow-Launcher/Flow.Launcher#4298

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Prevents a crash and error dialog on Windows theme/accent color change by treating WPF’s Color→Expression InvalidCastException from SystemResources.InvalidateTreeResources as recoverable and logging it. Closes Flow-Launcher/Flow.Launcher#4298.

- **Bug Fixes**
  - Added ExceptionHelper.IsRecoverableSystemResourceException to detect this framework-level exception.
  - Updated ErrorReporting to log and skip the error dialog for this case.

<sup>Written for commit 372f142b49e00e2e5210eed3e401137c5c430a67. Summary will update on new commits.</sup>

<!-- End of auto-generated description by cubic. -->

@prlabeler prlabeler Bot added the bug Something isn't working label Feb 27, 2026
@github-actions github-actions Bot added this to the 2.2.0 milestone Feb 27, 2026
…validation on Windows theme change

Co-authored-by: Jack251970 <53996452+Jack251970@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix casting exception for System.Windows.Media.Color Suppress spurious error dialog on Windows theme/accent color change Feb 27, 2026
@Jack251970 Jack251970 closed this Feb 27, 2026
@jjw24 jjw24 removed this from the 2.2.0 milestone Mar 1, 2026
@jjw24 jjw24 removed the 1 min review label Mar 1, 2026
@Jack251970 Jack251970 removed the bug Something isn't working label Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants