C# – Can’t see the designer view in Visual Studio 2008 C# Windows Forms due to weird error

cnetvisual studiovisual-studio-2008winforms

when I try to click on the designer tab to get the designer view, I get this error:

To prevent possible data loss before
loading the designer, the following
errors must be resolved:
The designer could not be shown for this file because none of the
classes within it can be designed. The
designer inspected the following
classes in the file: Form1 — The
base class 'System.Windows.Forms.Form'
could not be loaded. Ensure the
assembly has been referenced and that
all projects have been built.

I'd like to get into the designer and have no idea what's wrong. My Form1 code looks like this at the top:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Diagnostics;

    namespace foobar
    {
        public partial class Form1 : Form
        {

        List<CharLabel> allChars = new List<CharLabel>();

        public Form1()
        {
... etc ...

Any ideas?

Best Answer

When you change the namespace or other item inside a partial class (like Forms) directly from the code editor you are making an invitation for madness. As the name suggest a partial class is a class that is defined "partially" on the code view, but there is another part which is generated automaticall by VS and that is the other part of the class. In that part it contains the definition of all UI elements, fonts, default values, etc. When you change the name space in one part of the class the other part don't know what do and then the interesting errors start. When changing namespaces, class names, event methods names always use the Refactor option in VS.

In your case, I would probably go back to the old name it had, and then use Refactor option VS provides (Highlight the component name, Ricgh click, refactor->rename)

Hope this help.