0

I'm converting an old winforms application from 4.8 to 6.0.1. The conversion has been incredibly easy and the application worked with no problems at all until, suddenly, Visual Studio (2022 64-bit v17.0.5) refuses to show the form designer for every form inherits from another.

I scaled down my project until I discovered that it wasn't me...

using System.Windows.Forms;

namespace MyApp
{
    public partial class BaseForm : Form
    {
        public BaseForm()
        {
            InitializeComponent();
        }
    }
}

and

namespace MyApp
{
    public partial class ChildForm : BaseForm
    {
        public ChildForm()
        {
            InitializeComponent();
        }
    }
}

The other portion of every class (winforms splits the form class in two partials) are perfectly untouched.

The two forms are completely empty but the designer refuses to draw ChildForm returning this nice and senseless message:

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: 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: \r\n ChildForm --- The base class 'MyApp.BaseForm' could not be loaded. Ensure the assembly has been referenced and that all projects have been built. enter image description here

I've already tried everything I found on the Internet:

  • clean and rebuild the solution
  • exit from VS
  • put an explicit (and useless) :base() instruction on the ctor of the two forms
  • empty the cryptic folder C:\Users[me]\AppData\Local\Temp\WinFormsCache\

and many other tricks I found with no result at all.

The only things I haven't tried (yet) have been:

I haven't done those yet because the problem should be easy to fix. Reading the message it seems that the designer lost its ability to probe for assemblies and to read for types inside an assembly it have already referenced but this is true for an inherited form only. Crazy enough to investigate. Let's see if someone has already discovered the nth foolishness MS has been able to do.

epikarma
  • 41
  • 1
  • 7
  • I wouldn't beat myself up too hard about the net core/5+ winforms dev experience being comparatively unreliable; it really is just because it's buggy/unreliable - probably "a bit better than beta" grade atm. (And would I upgrade a netfw48 winforms app to net5+? Not right now!) – Caius Jard Jan 19 '22 at 19:27
  • I don't agree with you. According to my experience the upgrade assistant works like a charm, way better than I expected. The 6.0 runtime executes the converted program faster than the original .NET framework. Even the designer worked very well as the original one... the problem is that it is now stuck with the inheritance thing and I can't unlock it. IMHO the porting option is mature enough except for some little details. – epikarma Jan 19 '22 at 22:37

1 Answers1

2

Check your partial classes inherit the base form as well. I just created a .Net 6.0 win forms project and have these four classes working.

BaseForm.designer.cs
namespace WinFormsApp1 {
    partial class BaseForm {
        private System.ComponentModel.IContainer components = null;
        protected override void Dispose(bool disposing) {
            if (disposing && (components != null)) {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

    #region Windows Form Designer generated code

    private void InitializeComponent() {
        this.components = new System.ComponentModel.Container();
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(800, 450);
        this.Text = "Base Form";
    }

    #endregion
}
}

BaseForm.cs
namespace WinFormsApp1 {
public partial class BaseForm : Form {
    public BaseForm() {
        InitializeComponent();
    }
}
}

Form1.designer.cs
namespace WinFormsApp1 {
partial class Form1 : BaseForm {
    private System.ComponentModel.IContainer components = null;
    protected override void Dispose(bool disposing) {
        if (disposing && (components != null)) {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code
    private void InitializeComponent() {
        this.components = new System.ComponentModel.Container();
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(800, 450);
        this.Text = "Form1";
    }

    #endregion
}
}

Form1.cs
namespace WinFormsApp1 {
public partial class Form1 : BaseForm {
    public Form1() {
        InitializeComponent();
    }
}

}

Form 1 Inheriting BaseForm

Josh
  • 10,352
  • 12
  • 58
  • 109
  • Unfortunately your workaround doesn't work in my case. And it doesn't work even if I create a form without the partial with the InitializeComponent() method inside the main class. Anyway I believe your project works... mine worked well too before the crash. – epikarma Jan 20 '22 at 07:01