Error creating window handle in unit tests

23 hours ago 3
ARTICLE AD BOX

I have some unit tests that are testing a .NET 4.8 Windows Forms application.

Some of these tests construct an instance of a form and perform tests on various logic. The constructor calls InitializeComponent which allocates the controls which some of the tests need access to.

My problem is that when run on a build agent under github actions
(locally deployed Github Enterprise. Build agents are all Windows Server 2019), some of the tests throw an "Error creating window handle" when trying to create the controls. Everything runs fine locally.

I've checked all the obvious thing as well as some non-obvious things that Google suggested.

Every test has a using on the form creation so I know things are getting disposed.

I've checked the per-process User Handle and GDI handle limits, they're the default 10,000 on the agent.

I've added a check in the Setup function so every unit test prints out the value of Process.GetCurrentProcess().HandleCount to the console and therefore shows up in the build logs. There is a slight increase over time, but it maxes out around 1250, so not actually running out of handles.

I've checked the "Desktop Heap" and it's the same on my laptop vs the build agent.

It'll run several hundred tests with no problem before they start failing. Once it starts failing, they don't all fail. A few pass with no problem.

I considered that the build agent is "headless" and maybe it can't create the form because there's no way to display it. But hundreds of tests that do the same thing work just fine.

Any suggestions?

Read Entire Article