question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[dotnet-sdk-7.0.100-alpha.1.21568.2] WinForms Samples app launch failed with error System.ComponentModel.Win32Exception (1400): Error creating window handle

See original GitHub issue

Description

When testing WinForms Samples app against runtime dotnet-sdk-7.0.100-alpha.1.21568.2, it failed to launch with error System.ComponentModel.Win32Exception

Reproduction Steps

App Source, App checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1458251 Repro Steps for the Problematic App: Copy Apps\Winforms Samples from server to local machine. Launch MatchingGame.exe from Winforms Samples\matching-game

Minimal Repro steps: 1.Create a .NET 5.0 WinForm project. 2.Install MetroFramework nuget package from nuget.org. 3.Update the Form1.cs to inherit from MetroForm:

public partial class Form1 : MetroForm
    {
        public Form1()
        {
            InitializeComponent();
        }
    }

4.Build the project to generate WinFormApp1.exe 5.Launch the exe on a machine that only dotnet-sdk-7.0.100-alpha.1.21568.2 installed

Expected behavior

App launch successful.

Actual behavior

Launch failed with error

Regression?

Verify Scenarios: 1). Windows10 RS5 x64+dotnet-sdk-7.0.100-alpha.1.21568.2:Fail 2). Windows10 RS5 x64+dotnet-sdk-6.0.200-preview.21603.2: Pass

Known Workarounds

No response

Configuration

Application Name: WinForms Samples OS: Windows 10 RS5 CPU: X64 .NET Build Number: dotnet-sdk-7.0.100-alpha.1.21568.2

Other information

  1. Launch failed with MatchingGame.exe: If we launch the dll with dotnet command from command prompt window, we will get below error message:
Unhandled exception. System.ComponentModel.Win32Exception (1400): Error creating window handle.
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Form.CreateHandle()
   at System.Windows.Forms.Control.get_Handle()
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at MetroFramework.Forms.MetroForm.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)
   at MatchingGame.Program.Main() in C:\.NETCoreUpgradeApps\AppSources\samples\windowsforms\matching-game\net5-windows\cs\MatchingGame\Program.cs:line 13

And we found this issue is caused by MetroFramework nuget package used in the project. But this package only one version. NuGet Gallery | MetroFramework 1.2.0.3

2)Launch failed with error with minimal demo WinFormsApp1.exe:

Application: WinFormsApp1.exe
CoreCLR Version: 7.0.21.56701
.NET Version: 7.0.0-alpha.1.21567.1
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ComponentModel.Win32Exception (1400): Error creating window handle.
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Form.CreateHandle()
   at System.Windows.Forms.Control.get_Handle()
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at MetroFramework.Forms.MetroForm.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)
   at WinFormsApp1.Program.Main() in E:\App Source\WinFormsApp1\WinFormsApp1\Program.cs:line 20

When using Windbg to launch the minimal demo WinFormsApp1.exe, we will get these:

(4f10.ba4): CLR exception - code e0434352 (first chance)
(4f10.ba4): CLR exception - code e0434352 (!!! second chance !!!)
CLR exception type: System.ComponentModel.Win32Exception
    "Error creating window handle."
*** WARNING: Unable to verify checksum for C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.0-alpha.1.21567.1\coreclr.dll
*** WARNING: Unable to verify checksum for C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\7.0.0-alpha.1.21566.3\System.Windows.Forms.dll
KERNELBASE!RaiseException+0x69:
00007fff`91c24f69 0f1f440000      nop     dword ptr [rax+rax]
0:000> k
*** WARNING: Unable to verify checksum for C:\Appcompat\applications\net5.0-windows\WinFormsApp1.dll
*** WARNING: Unable to verify checksum for C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.0-alpha.1.21567.1\hostpolicy.dll
*** WARNING: Unable to verify checksum for C:\Program Files\dotnet\host\fxr\7.0.0-alpha.1.21567.1\hostfxr.dll
*** WARNING: Unable to verify checksum for apphost.exe
 # Child-SP          RetAddr               Call Site
00 000000c8`5a37dfe0 00007fff`34ceeeb5     KERNELBASE!RaiseException+0x69
01 000000c8`5a37e0c0 00007fff`34dde3df     coreclr+0x4eeb5
02 000000c8`5a37e1b0 00007fff`0cb26c39     coreclr!coreclr_initialize+0x653ff
03 000000c8`5a37e310 00007fff`0c9c2637     System_Windows_Forms!
04 000000c8`5a37e3f0 00007fff`0cac7c1b     System_Windows_Forms!
05 000000c8`5a37e4b0 00007fff`0c9bd030     System_Windows_Forms!
06 000000c8`5a37e520 00007fff`0c9cf6c6     System_Windows_Forms!
07 000000c8`5a37e560 00007fff`0cac5d23     System_Windows_Forms!
08 000000c8`5a37e650 00007ffe`d5264456     System_Windows_Forms!
09 000000c8`5a37e6b0 00007fff`0cc78f99     MetroFramework!
0a 000000c8`5a37e6f0 00007fff`0cc78e58     System_Windows_Forms!
0b 000000c8`5a37e790 00007ffe`d524a093     System_Windows_Forms!
0c 000000c8`5a37e7f0 00007fff`34e04cf3     WinFormsApp1!
0d 000000c8`5a37e830 00007fff`34cb07b8     coreclr!MetaDataGetDispenser+0x12053
0e 000000c8`5a37e870 00007fff`34d7c97b     coreclr+0x107b8
0f 000000c8`5a37e9b0 00007fff`34d7c7fa     coreclr!coreclr_initialize+0x399b
10 000000c8`5a37eae0 00007fff`34d7c4ad     coreclr!coreclr_initialize+0x381a
11 000000c8`5a37eb90 00007fff`34d7bf76     coreclr!coreclr_initialize+0x34cd
12 000000c8`5a37ef20 00007fff`34d78c92     coreclr!coreclr_initialize+0x2f96
13 000000c8`5a37f090 00007fff`4fb5926b     coreclr!coreclr_execute_assembly+0xe2
14 000000c8`5a37f130 00007fff`4fb5959c     hostpolicy+0x1926b
15 000000c8`5a37f2d0 00007fff`4fb59f37     hostpolicy+0x1959c
16 000000c8`5a37f310 00007fff`4fbbb539     hostpolicy!corehost_main+0x107
17 000000c8`5a37f4c0 00007fff`4fbbe506     hostfxr!hostfxr_close+0xfb9
18 000000c8`5a37f5c0 00007fff`4fbc0821     hostfxr!hostfxr_close+0x3f86
19 000000c8`5a37f6c0 00007fff`4fbbeb62     hostfxr!hostfxr_close+0x62a1
1a 000000c8`5a37f770 00007fff`4fbb82ab     hostfxr!hostfxr_close+0x45e2
1b 000000c8`5a37f8b0 00007ff6`0acadc1c     hostfxr!hostfxr_main_startupinfo+0xab
1c 000000c8`5a37f9b0 00007ff6`0acadf81     apphost+0xdc1c
1d 000000c8`5a37fba0 00007ff6`0acaf4f8     apphost+0xdf81
1e 000000c8`5a37fd10 00007fff`92447034     apphost+0xf4f8
1f 000000c8`5a37fd50 00007fff`93f62651     KERNEL32!BaseThreadInitThunk+0x14
20 00000000`00000000 00000000`00000000     0x0

@dotnet-actwx-bot @dotnet/compat

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:23 (22 by maintainers)

github_iconTop GitHub Comments

4reactions
Olina-Zhangcommented, Jan 11, 2022

And also verified this issue using that testing app with MetroFramework nuget package on a just .Net 6.0 SDK: 6.0.200-preview.22055.15, it cannot repro.

2reactions
roland5572commented, Jan 11, 2022

@Tanya-Solyanik Missing this statement can make the program unstable, but it won’t fire 100% of the time. I’ll try this bug again in the next few days. I’m not sure if the current .NET version has fixed this. If it still happens, I will create a new post.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Winforms issue - Error creating window handle [duplicate]
The windows handle limit for your application is 10,000 handles. You're getting the error because your program is creating too many handles.
Read more >
Help! Microsoft.Net: Error Creating Window Handle
System.ComponentModel.Win32Exception: Error creating window handle. at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp).
Read more >
'Error creating window handle.' : r/csharp
System.ComponentModel.Win32Exception: 'Error creating window handle.' hello, so as the title says, I am facing this issue when trying to ...
Read more >
Error Creating Window Handle
Let me start by saying I am not an experienced developer and by no means a C# expert. I have created a winform...
Read more >
Win32Exception (Error creating window handle) in ...
Hello. I have a problem with SchedulerControl TimelineView. I have a big application build with WinForms, using a lot of DevExpress ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found