2
votes

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?

3

3 Answers

3
votes

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.

2
votes

Have you checked the recomendation in the message? That is, have you verified that System.Windows.Forms.dll is referenced in your project?

To add the reference if it's missing do the following

  • Click: View -> Solution Explorer
  • Right Click on the References node and select "Add Referenc"
  • Go to the .Net Tab
  • Scroll until you see System.Windows.Forms.dll
  • Select that and hit OK
0
votes

I'd experienced this too, i solved it by correcting referenced libraries absence.

You may check your Error List.