Window class name is not valid.

I get this error about 75% of the time I try to debug in Visual Studio 2005.  I have reinstalled VS and applied the latest service pack with no relief.  It never happens if I run without debugging, only when I try to debug.   It happens with every project I create, it's not isolated to a single project or solution.  Any help is greatly appreciated.

It’s always thrown on this line (or equivalent):

public static void Main(string[] args)

{

Application.Run(new MainForm());

}

System.ComponentModel.Win32Exception was unhandled
  Message="Window class name is not valid."
  Source="System.Windows.Forms"
  ErrorCode=-2147467259
  NativeErrorCode=0
  StackTrace:
       at System.Windows.Forms.NativeWindow.WindowClass.RegisterClass()
       at System.Windows.Forms.NativeWindow.WindowClass.Create(String className, Int32 classStyle)
       at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
       at System.Windows.Forms.Control.CreateHandle()
       at System.Windows.Forms.TreeView.CreateHandle()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at JCARepository.MainForm.Main(String[] args) in C:\Documents and Settings\John\My Documents\JCA\Repository\new\MDIClient\Form1.cs:line 266
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()




Answer this question

Window class name is not valid.

  • Ray_bihpgh20

    Moving to a more appropriate forum ...
  • danilomunoz

    Looks like the native InitCommonControlsEx() is failing. It is called by the TreeView's CreateHandle() override but the framework doesn't check the return value. Sloppy. As to why it is failing: tough call. Start by taking a good hard look at c:\windows\system32\comctl32.dll. It is prone to be mangled by crummy install programs. Mine is XP SP2, V5.82.2900.2180, 8/10/2004, 5am. There's a backup copy in c:\windows\system32\dllcache. The application manifest plays a role too. And you may have some crumware allocating too many handles.


  • Gamargia

    I have started a microsoft support service for this issue. I directed the support person to this thread as well as many other i have found. he has looked them over and is trying to replicate this. i will post whatever he comes up with on this thread.

    Joe

    p.s. my earlier post was wrong: it it NOT just linked to the treeview control. i can get it to happen with a blank project and any control added.


  • Melissa H.

    You are right about it being linked to the TreeView, i think. All of my projects that do NOT have a TreeView in them work fine. Any project with a TreeView has this intermittent problem that will not go away. it happens more than 50% of the time...

    the comctl32.dll is 5.82.2900.2982 - seems fine.

    do you have any more suggestions on this topic

    Thanks,

    Joe


  • Helmut Leitner

    One other thing. I saw, either in this thread or another about the same problem, that someone had found if they comment out the Application.EnableVisualStyles(); line, the problem went away. This works for me also:

    //Application.EnableVisualStyles();

    Application.SetCompatibleTextRenderingDefault(false);

    Application.Run(new Form1());

    I sent this to the tech support working on the problem; hopefully it helps them. In the mean time, that is what i am doing during debugging...


  • Eirian

    You also might want to play with your Windows Theme to see if it makes a difference. Control Panel + Display, "Themes" tab. Windows Blinds is known to be trouble.


  • LynnOoi

    That version is not listed in the Microsoft's DLL database but I found it included in a security patch (ms06-057). Only seeing this on a TreeView is mighty odd, other controls call InitializeCommonControlsEx() too. There is some monkeying going on with Visual Styles, a fertile feature for bugs. Try turning it off.


  • Nate00

    I am getting the same thing in the C# Winforms designer.

    Let me just say that I think the VS2005 designer is a disaster. If it works at runtime, it should work at design time, I shouldn't have to spend time writing code to make the IDE work. I did report this as a bug, and was told it's a 'feature'. No, it's not. It's stupid.

    I need to deliver this tomorrow, and instead of writing code, I am fighting the IDE.



  • ShadowRayz

    I am having the same problem. I even created a brand new project with nothing in it and can't run it now.

    If I try to run it over and over again, eventually it will run.

    Really frustrating.


  • jongas

    Here's another stack from a different project, same problem:

    System.ComponentModel.Win32Exception was unhandled
    Message="Window class name is not valid."
    Source="System.Windows.Forms"
    ErrorCode=-2147467259
    NativeErrorCode=0
    StackTrace:
    at System.Windows.Forms.NativeWindow.WindowClass.RegisterClass()
    at System.Windows.Forms.NativeWindow.WindowClass.Create(String className, Int32 classStyle)
    at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
    at System.Windows.Forms.Control.CreateHandle()
    at System.Windows.Forms.TextBoxBase.CreateHandle()
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
    at System.Windows.Forms.Control.CreateControl()
    at System.Windows.Forms.Control.WmShowWindow(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.ContainerControl.WndProc(Message& m)
    at System.Windows.Forms.Form.WmShowWindow(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
    at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
    at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
    at System.Windows.Forms.Control.set_Visible(Boolean value)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.Run(Form mainForm)
    at ModuleLoader.Program.Main() in C:\Documents and Settings\John\My Documents\JCA\Repository\JcaRepositoryService\ModuleLoader\Program.cs:line 17
    at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()



  • rgsjr

    I'm still cursed by this problem. It's not just the treeview, I get the error if i only add one button to a form with no code at all.

  • av_ster

    Yes, please let us know. S/he'll have trouble reproducing the issue, invite them to dial into your PC.


  • creaturita

    still working with the support.

    i have not been able to reproduce the error in safe mode or safe mode with networking. has anyone else


  • JSantos196912

    There are not a lot of ways to move ahead with this. My guess is that some kind of DLL or program is interfering, impossible to troubleshoot long distance. You could call Microsoft Support, they'll take $150 or so off your credit card. You'll get it back if it is their bug (not likely). If that's too rich for your taste, consider re-installing Windows after you tried uninstalling as much as you can (including virus checkers).


  • Window class name is not valid.