Skip to content

System.Runtime.InteropServices.ExternalException : A generic error occurred in GDI+ #58741

@StefanKoell

Description

@StefanKoell
  • .NET Core Version:
    Microsoft.WindowsDesktop.App 5.0.9

  • Have you experienced this same bug with .NET Framework?:
    No

Problem description:
I switched my WinForms App from .NET 4.71 to .NET 5 and get the following crashes from my user's machine:

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
Source: System.Drawing.Common
    -- get_ErrorCode = -2147467259 (0x80004005)   [int]
    -- get_HResult = -2147467259 (0x80004005)   [int]
 at [System.Drawing.Common] System.Drawing.Graphics void CheckErrorStatus(int )
 at [System.Drawing.Common] System.Drawing.Graphics void FillRectangle(System.Drawing.Brush ,System.Drawing.Rectangle )

From the stack trace, I can see that this crash almost always originates from showing a messagebox (drawing the background). Since I'm not able to reproduce the crash myself, I reached out to my users and I was at least able to find a common pattern:

  • Many users told me that the crash happens when the machine has been in sleep mode and wakes up. My app would show a message box when a network connection is interrupted, so this makes sense.
  • Some users reported that the crash happens when Windows tries to shutdown/reboot while my app is running.
  • Some users reported that the crash happens when my app is set to auto-run and shows the first dialog (password prompt). In this case it seems that the app has been started while the login screen is still shown.

Judging from the user reports, I guess this crash mostly happens when the "desktop" is "hidden" or not shown (like lock screen when the machine enters sleep mode, login screen, the screen shown when you shutdown/reboot Windows).

I'm not sure how to further troubleshoot the issue or resolve the issue.

Minimal repro:
Unfortunately I'm not able to reliably reproduce the issue myself.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions