Skip to content

GDI+ Exception drawing SplitContainer when PC Locked #14562

Closed

Description

@djoyner-aveva

.NET version

.NET 10

Did it work in .NET Framework?

Not tested/verified

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Also reproduced in .NET 8

Issue description

We have a WPF application that has a window containing a WindowsFormsHost that contains a WinForms UserControl that contains a WinForms SplitContainer. If the computer is locked before the window layout has completed then the following exception occurs

Image

Full callstack is

Warning: 0 : [FCE]:ExternalException: A generic error occurred in GDI+.
at System.Drawing.Graphics.CheckErrorStatus(System.Char[])
at System.Drawing.Graphics.FillRectangle(System.Char[])
at System.Windows.Forms.SplitContainer.RepaintSplitterRect(System.Char[])
at System.Windows.Forms.SplitContainer.ResizeSplitContainer(System.Char[])
at System.Windows.Forms.SplitContainer.OnLayout(System.Char[])
at System.Windows.Forms.Control.PerformLayout(System.Char[])
at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(System.Char[])
at System.Windows.Forms.ScrollableControl.OnVisibleChanged(System.Char[])
at System.Windows.Forms.Control.OnVisibleChanged(System.Char[])
at System.Windows.Forms.Control.OnVisibleChanged(System.Char[])
at System.Windows.Forms.Control.OnVisibleChanged(System.Char[])
at System.Windows.Forms.Control.WndProc(System.Char[])
at System.Windows.Forms.ScrollableControl.WndProc(System.Char[])
at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Char[])
at System.Windows.Forms.NativeWindow.Callback(System.Char[])
at System.Windows.Forms.Integration.WindowsFormsHost.BuildWindowCore(System.Char[])
at System.Windows.Interop.HwndHost.BuildWindow(System.Char[])
at System.Windows.Interop.HwndHost.BuildOrReparentWindow(System.Char[])
at System.Windows.RoutedEventArgs.InvokeHandler(System.Char[])
at System.Windows.EventRoute.InvokeHandlersImpl(System.Char[])
at System.Windows.UIElement.RaiseEventImpl(System.Char[])
at System.Windows.PresentationSource.UpdateSourceOfElement(System.Char[])
at System.Windows.PresentationSource.OnVisualAncestorChanged(System.Char[])
at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(System.Char[])
at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(System.Char[])
at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(System.Char[])
at System.Windows.Media.Visual.AddVisualChild(System.Char[])
at System.Windows.Controls.ContentPresenter+UseContentTemplate.BuildVisualTree(System.Char[])
at System.Windows.StyleHelper.ApplyTemplateContent(System.Char[])
at System.Windows.FrameworkTemplate.ApplyTemplateContent(System.Char[])
at System.Windows.FrameworkElement.ApplyTemplate(System.Char[])
at System.Windows.FrameworkElement.MeasureCore(System.Char[])
at System.Windows.UIElement.Measure(System.Char[])
at System.Windows.Controls.Border.MeasureOverride(System.Char[])
at System.Windows.FrameworkElement.MeasureCore(System.Char[])
at System.Windows.UIElement.Measure(System.Char[])
at System.Windows.Controls.Page.MeasureOverride(System.Char[])
at System.Windows.FrameworkElement.MeasureCore(System.Char[])
at System.Windows.UIElement.Measure(System.Char[])
at MS.Internal.Helper.MeasureElementWithSingleChild(System.Char[])
at System.Windows.FrameworkElement.MeasureCore(System.Char[])
at System.Windows.UIElement.Measure(System.Char[])
at System.Windows.ContextLayoutManager.UpdateLayout(System.Char[])
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(System.Char[])
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks(System.Char[])
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(System.Char[])
at System.Windows.Media.MediaContext.RenderMessageHandler(System.Char[])
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Char[])
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Char[])
at System.Windows.Threading.DispatcherOperation.InvokeImpl(System.Char[])
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Char[])
at System.Threading.ExecutionContext.RunInternal(System.Char[])
at MS.Internal.CulturePreservingExecutionContext.Run(System.Char[])
at System.Windows.Threading.DispatcherOperation.Invoke(System.Char[])
at System.Windows.Threading.Dispatcher.ProcessQueue(System.Char[])
at System.Windows.Threading.Dispatcher.WndProcHook(System.Char[])
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Char[])
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Char[])
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Char[])
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Char[])
at MS.Win32.HwndSubclass.SubclassWndProc(System.Char[])
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Char[])
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Char[])
at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Char[])
at System.Windows.Application.RunDispatcher(System.Char[])
at System.Windows.Application.RunInternal(System.Char[])
at Spiral.Suite.Sandbox.App.Main(System.Char[])

Warning: 0 : [FCE]:ExternalException: A generic error occurred in GDI+.
at System.Windows.Forms.NativeWindow.Callback(System.Char[])
at System.Windows.Forms.Integration.WindowsFormsHost.BuildWindowCore(System.Char[])
at System.Windows.Interop.HwndHost.BuildWindow(System.Char[])
at System.Windows.Interop.HwndHost.BuildOrReparentWindow(System.Char[])
at System.Windows.RoutedEventArgs.InvokeHandler(System.Char[])
at System.Windows.EventRoute.InvokeHandlersImpl(System.Char[])
at System.Windows.UIElement.RaiseEventImpl(System.Char[])
at System.Windows.PresentationSource.UpdateSourceOfElement(System.Char[])
at System.Windows.PresentationSource.OnVisualAncestorChanged(System.Char[])
at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(System.Char[])
at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(System.Char[])
at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(System.Char[])
at System.Windows.Media.Visual.AddVisualChild(System.Char[])
at System.Windows.Controls.ContentPresenter+UseContentTemplate.BuildVisualTree(System.Char[])
at System.Windows.StyleHelper.ApplyTemplateContent(System.Char[])
at System.Windows.FrameworkTemplate.ApplyTemplateContent(System.Char[])
at System.Windows.FrameworkElement.ApplyTemplate(System.Char[])
at System.Windows.FrameworkElement.MeasureCore(System.Char[])
at System.Windows.UIElement.Measure(System.Char[])
at System.Windows.Controls.Border.MeasureOverride(System.Char[])
at System.Windows.FrameworkElement.MeasureCore(System.Char[])
at System.Windows.UIElement.Measure(System.Char[])
at System.Windows.Controls.Page.MeasureOverride(System.Char[])
at System.Windows.FrameworkElement.MeasureCore(System.Char[])
at System.Windows.UIElement.Measure(System.Char[])
at MS.Internal.Helper.MeasureElementWithSingleChild(System.Char[])
at System.Windows.FrameworkElement.MeasureCore(System.Char[])
at System.Windows.UIElement.Measure(System.Char[])
at System.Windows.ContextLayoutManager.UpdateLayout(System.Char[])
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(System.Char[])
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks(System.Char[])
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(System.Char[])
at System.Windows.Media.MediaContext.RenderMessageHandler(System.Char[])
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Char[])
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Char[])
at System.Windows.Threading.DispatcherOperation.InvokeImpl(System.Char[])
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Char[])
at System.Threading.ExecutionContext.RunInternal(System.Char[])
at MS.Internal.CulturePreservingExecutionContext.Run(System.Char[])
at System.Windows.Threading.DispatcherOperation.Invoke(System.Char[])
at System.Windows.Threading.Dispatcher.ProcessQueue(System.Char[])
at System.Windows.Threading.Dispatcher.WndProcHook(System.Char[])
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Char[])
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Char[])
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Char[])
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Char[])
at MS.Win32.HwndSubclass.SubclassWndProc(System.Char[])
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Char[])
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Char[])
at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Char[])
at System.Windows.Application.RunDispatcher(System.Char[])
at System.Windows.Application.RunInternal(System.Char[])
at Spiral.Suite.Sandbox.App.Main(System.Char[])

An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Windows.Forms.dll
A generic error occurred in GDI+.

Steps to reproduce

Build the attached solution.
Run the LockCrash executable outside of the debugger.
Press the button to launch the window then lock the PC.
When you unlock the PC again you will see the unhandled exception dialog.
LockCrash.zip

Activity

  1. added
    untriaged
    on May 26, 2026
  2. LeafShi1 commented on May 26, 2026

    @LeafShi1
    Member

    @djoyner-aveva I followed the provided repro steps (including running the executable outside of the debugger and locking/unlocking the PC), but I was not able to reproduce the issue on my environment.

    Since this seems to be related to GDI+/rendering during lock screen transitions, environment differences may be a factor.

    Could you please confirm:

    • Are you running on a physical machine or a virtual machine?
    • OS version
    • GPU / display configuration (single monitor vs multi-monitor, DPI settings)
    • Whether it happens consistently or intermittently

    These details may help narrow down whether the issue is related to graphics context transitions.

  3. djoyner-aveva commented on May 26, 2026

    @djoyner-aveva
    Author

    @LeafShi1 thanks for looking at the issue. I'm running Win11 Build 26200.8390. I'm running directly on a physical laptop. I can reproduce on the laptop screen and also when I'm plugged into an external monitor. It's consistent, and has also been observed by a number of my colleagues.

    You need to lock the device before the new window is shown (there's a two second delay built in to the application).

  4. self-assigned this
    on May 27, 2026
  5. removed
    untriaged
    on Jul 1, 2026
  6. Amy-Li03 commented on Jul 3, 2026

    @Amy-Li03
    Contributor

    Tested above demo app in the latest .NET 11 Preview 7 build: 11.0.100-preview.7.26352.103 + built private dls from the main branch of WinForms repo, issue was fixed, after lock and unlock the PC, we don't see the unhandled GDI+ exception dialog.

  7. added this to the 11.0-preview7 milestone on Jul 3, 2026
  8. Amy-Li03 commented on Aug 3, 2026

    @Amy-Li03
    Contributor

    Verified on .NET 11 Preview 7 test pass build: .NET 11.0.100-preview.7.26381.103, issue was fixed.

  9. locked and limited conversation to collaborators on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Drawing

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions