Cannot Display Inherited Form in Form Designer When Base Form Defined in an Assembly for Visual Studio 2022
Asked Answered
S

1

6

MyForm is inherited from Form. I am able to inherit MyForm in VS2022 application. However, if MyForm is inside a library and my VS2022 application tries to create a form that is inherited from MyForm then I got an error:

"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 base class '' could not be loaded. Ensure the assembly has been referenced and that all projects have been built. "

I would think this is a bug in VS2022 latest version. I have no issue in Visual Studio 2019/2010 Any work around for this issue would be great.

Thanks

Sam answered 10/2, 2022 at 16:45 Comment(2)
I get this error even if I add the inherited form via Visual Studio itself: Project -> Add -> New Item -> Inherited Form (Windows Forms), and point it to my base form when prompted. It should be embarrassing to Microsoft that this is so broken. There is nothing special about my base form (no overloaded constructor or anything manually changed).Apicella
I had the same problem. After spending hours of search and try, one tip worked: remove all build errors and then try to open forms. In my case, it worked. I had to comment some statements since they needed longer time to fix.Gothic
A
6

It seems this a Visual Studio 2022 bug that affects only inherited forms whenever their base classes are stored on x86 dll assemblies.

As of today, using Microsoft Visual Studio Professional 2022 (64-bit) - Version 17.3.3, C# Form Designer is unable to design/load previous forms.

Fortunately there are several workarounds.

Workaround 1 (VS2022)

On Configuration Manager, locate the project that contains your form base class (the form class which your offending form as inherited from) and change Platform from Any CPU to x86, save and rebuild it. Your target form should load ok.

enter image description here

Workaround 2 (VS2022)

One guy, Frank Wenzl, figured out that changing Output type from Class Library (.dll) to Windows Application (.exe) on the project that contains the form base class and rebuilding it, allow Windows Form Designer to load inherited forms normally.

enter image description here

Workaround 3 (VS2019 or prior versions)

Using Microsoft Visual Studio Professional 2019 (32 bit, i guess) - Version 16.9.4, C# Form Designer allowed me to proceed my work.

For further info on this issue, check:

Armyworm answered 1/9, 2022 at 8:6 Comment(1)
I am migrating a Windows Forms application developed in .Net Framework 4.6 in Visual Studio 2019. There is a parent form (containing nothing but utility methods needed on forms) and all forms inherit from it. Now in new environment (Windows Forms app in .Net 7 and VS2022), no child form opens in design mode giving error "The base class 'xyz' could not be loaded. Ensure the assembly has been referenced and that all projects have been built. I have tried almost all tricks available on the internet but nothing worked. Please suggest some solution.Gothic

© 2022 - 2024 — McMap. All rights reserved.