Skip to content

Circular Reference Exception in Window Style Property When Connecting via Remote Desktop #11530

@cqchenxi

Description

@cqchenxi

Description

When connecting to a host running a WPF application via Remote Desktop Protocol (RDP), the application may throw a System.InvalidOperationException indicating a circular reference was detected while calculating the Style property of a Window element.

Reproduction Steps

  1. Launch a WPF application with Fluent theme enabled
  2. Connect to the host running the application via Remote Desktop Connection (RDP)
  3. Upon establishing the RDP connection, a system theme change event is triggered
  4. The application may throws an exception

Expected behavior

When connecting via Remote Desktop, the application should smoothly handle system theme changes and update Fluent theme resources without throwing exceptions.

Actual behavior

System.InvalidOperationException: 在计算元素"System.Windows.Window"上的 Style 属性时发现循环引用。
at System.Windows.FrameworkElement.UpdateStyleProperty()
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.DescendentsWalker1.StartWalk(DependencyObject startNode, Boolean skipStartNode) at System.Windows.TreeWalkHelper.InvalidateOnResourcesChange(FrameworkElement fe, FrameworkContentElement fce, ResourcesChangeInfo info) at System.Windows.Application.InvalidateResourceReferenceOnWindowCollection(WindowCollection wc, ResourcesChangeInfo info) at System.Windows.Application.InvalidateResourceReferences(ResourcesChangeInfo info) at System.Windows.ResourceDictionary.NotifyOwners(ResourcesChangeInfo info) at System.Windows.ResourceDictionary.OnMergedDictionariesChanged(Object sender, NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Windows.ThemeManager.AddOrUpdateThemeResources(ResourceDictionary rd, ResourceDictionary newDictionary)
at System.Windows.ThemeManager.OnSystemThemeChanged()
at System.Windows.SystemResources.SystemThemeFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, Int32 wParam, IntPtr lParam)

Regression?

No response

Known Workarounds

No response

Impact

The process was terminated due to an unhandled exception.

Configuration

OS: Windows 10 IoT 企业版 LTSC
.NET Version: .NET 9.0+
WPF Version: PresentationFramework.Fluent
Trigger Scenario: Remote Desktop Connection (RDP)

Other information

  • The IgnoreWindowResourcesChange flag is only set within AddOrUpdateThemeResources
  • However, resource change events propagate immediately, triggering window style updates
  • The style update attempts to reference the resource dictionary that is currently being replaced, creating a circular dependency

Metadata

Metadata

Assignees

No one assigned

    Labels

    InvestigateRequires further investigation by the WPF team.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions