주 콘텐츠로 건너뛰기

 none
Window class name is not valid. RRS feed

  • 질문

  • 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()

    2007년 1월 12일 금요일 오후 10:11

모든 응답

  • 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()

    2007년 1월 12일 금요일 오후 10:17
  •  

    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.

     

    2007년 1월 29일 월요일 오후 5:29
  • 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.

     

    2007년 1월 31일 수요일 오전 7:22
  • Moving to a more appropriate forum ...
    2007년 2월 5일 월요일 오후 7:22
  • 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.
    2007년 2월 5일 월요일 오후 9:26
    중재자
  • 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

    2007년 3월 30일 금요일 오후 7:36
  • 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.
    2007년 3월 30일 금요일 오후 8:03
    중재자
  • 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.
    2007년 4월 20일 금요일 오후 6:02
  • 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).
    2007년 4월 20일 금요일 오후 6:44
    중재자
  • 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.

    2007년 4월 26일 목요일 오후 1:22
  • Yes, please let us know.  S/he'll have trouble reproducing the issue, invite them to dial into your PC.
    2007년 4월 26일 목요일 오후 1:51
    중재자
  • 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?

     

     

    2007년 4월 30일 월요일 오후 8:39
  •  

    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... 

     

     

    2007년 5월 1일 화요일 오후 12:39
  • 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.
    2007년 5월 2일 수요일 오후 9:19
    중재자
  • They wanted me to check the same thing: i was on "Modified" and they asked me to change the theme to Windows XP - still have the same problem.  waiting for a response from them...
    2007년 5월 2일 수요일 오후 9:51
  • I got this very same error while trying to debug the MS QuickStart samples for the latest Enterprise Library 3.0.  Upon further inspection and some trial and error I noticed that their samples lack the following line:

     

    Application.EnableVisualStyles();

     

    This must be before any initial windows are created and therefore probably belongs as one of the first lines in your Main entry point method.  Once I added this line I cannot reproduce the error a single time.  My machine is a Dell Workstation M90 laptop running Vista 64-bit.  From reading all the different posts here and elsewhere about this problem, I'm inclined to think that it's isolated to 64-bit Vista, but I wouldn't swear on that.

     

    Anyway, this worked for me, so hope it helps.

    2007년 5월 4일 금요일 오전 1:15
  • Hi all. Commenting out the "Application.EnableVisualStyles()" did the trick for me. For months on end I had this problem with every form based .NET application when starting to debug. A single button would suffice to cause this problem - 2/3rds of my debug attempts would fail. I don't use any third party themes and I even had my designs service turned off until recently: The problem was always there, from the day I installed this notebook.

    Greets,

      giswizz

    2007년 5월 10일 목요일 오후 7:30
  • posted in the other thread as well....

     

    Worked with a Microsoft Support Person today on this.  He hooked up to my computer remotely and witnessed the problem.  The only thing we could find that eliminated the problem was to start the debugging without using the Visual Studio hosting process.  You can de-select this in the "Debug" tab of the properties window for the solution.

     

    This seems like an OK workaround as the there are only a couple main things you are not able to do when not using hosting, and i never use them anyway:

    • The time needed to begin debugging .NET Framework applications increases.

    • Design-time expression evaluation is unavailable.

    • Partial trust debugging is unavailable.

    someday i might reload XP and everything else from the ground up... but this is OK for now.

     

     

    2007년 8월 10일 금요일 오후 7:28
  • In vb.NET/VS2005 it is:

    'Me.EnableVisualStyles = true
    Me.EnableVisualStyles = False

    in the file Application.designer.vb

    This appears to override the XML values in Application.myapp:

    <EnableVisualStyles>true</EnableVisualStyles>

    Have had VS2005 installed since forever, so something new must have hosed a DLL up...
    • 답변으로 제안됨 1337CSS3 2009년 4월 29일 수요일 오후 10:23
    2009년 4월 21일 화요일 오후 11:13
  • As soon as I read this, I just hit Ctrl+F (Find), typed EnableVisualStyles, and told it to search the entire solution. This brought up Application.myapp, and just manually set the XML value to false. Thank you so much for posting this! I've practically doubled my efficency!


    >>(:-0)->-<
            |\
          _|  \_
         /        \     Got fire on the brain?
        |  Aah!  |
         \_____/
    • 편집됨 1337CSS3 2009년 4월 29일 수요일 오후 10:39 fixing pic
    2009년 4월 29일 수요일 오후 10:23
  • Removing webcam driver & software fixed it for me.

    After installing Visual Studio 2008, I got the same "Win32Exception was unhandled ... Window class name is not valid" error the first half-dozen times I tried to hit F-5 to debug/run my first ever "hello world" Visual Basic program.  

    After reading the posts above and some others, I first tried updating the driver for the Logitech webcam on my laptop, but got a message saying that the driver I had was newer than the one I was trying to install.  So then I uninstalled both webcam driver & software from my Dell laptop.  I re-booted, opened the "hello world" program in VS again, pressed F-5 for the 7th time, and it worked --- no error.

    Webcam specs:  Logitech Webcam Chat, M/N: V-UAP14, P/N 861193-1000, purchased 04/26/06
    Laptop specs:  Dell Lattitude 820 laptop, Core 2 CPU, purchased around 06/2007.
    O/S: XP Pro, v. 2002, SP3

    Thanks!
    2009년 5월 1일 금요일 오전 1:52
  • ... and:

    Software: VS 2008 Pro, SP1
    Other: .NET Framework, ver. 3.5 SP1
    2009년 5월 1일 금요일 오전 2:15
  • I also got the “Windows class name is not valid” error message when trying to run programs in debug mode. Also, when I ran a compiled program, I usually got an error message “(program name) has encountered a problem and needs to close.”

    Thanks to this forum, I was able to avoid the problem by running in Safe Mode, and was able to get work done until I had more time to work on the problem. Since programs ran OK in Safe Mode, I tried to find a program or service that caused the conflict.

    I first stopped all programs from running at Startup.  My Startup folder was empty, so I used msconfig (Start > Run > msconfig > Startup tab) to uncheck all 27 programs listed in the Startup tab. This did not help.

    I then disabled six tasks (Start > Programs > Accessories > System Tools > Scheduled Tasks). This did not help.

    I then looked at the large number of services which launch automatically at start-up. (Start > Run > services.msc). I paused or stopped each services shown as “Started”, one at a time (click to select the service, then change the status). After stopping a service, I checked for the problem.  Sometimes I did not have a problem until I tried a few times.  Finally, when I stopped the Process Monitor service, my programs ran consistently without an error message!

    Since I did not seem to need Process Monitor, I changed its setting from Automatic (launches at Startup) to Manual, meaning I have to start it myself. To do this in services.msc, right-click the Process Manager service, click Properties, under Startup Type, choose Manual.

    I do not know whether the Process Monitor directly confliced with VB, or whether stopping it freed up resouces needed by VB. Also, I am not sure whether stopping a different service would have had the same affect, since I quit stopping services when I found that Process Monitor did the trick.

    Thank you for your help in finding this solution.


    M. F. Heilweil

    2012년 12월 20일 목요일 오후 10:05