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.
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:
- reinstall VS
- going back to the previous version of my program
- give a try to this extension method approach https://stackoverflow.com/a/54184429/4894941
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.