My code worked fine in VS2022, now fails in VS 2026

MarkH-7032 0 Reputation points
2026-11-26T17:47:30.55+00:00

I get this 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: MainForm --- The base class 'System.Windows.Forms.Form' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.
--------
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other

A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.


2 answers

Sort by: Most helpful
  1. AI answer

    2026-11-26T17:48:30.4+00:00

    Clean and rebuild the entire solution first, because this message means the WinForms designer cannot load System.Windows.Forms.Form as the form’s design-time base class.

    1. Restore a buildable design-time assembly

    1. Close every open Form Designer tab.
    2. Select Build → Clean Solution.
    3. Select Build → Rebuild Solution.
    4. In View → Error List, select Entire Solution and fix every build error, including errors in referenced projects.
    5. Reopen MainForm with Solution Explorer → right-click MainForm.cs → View Designer.

    Microsoft’s designer guidance specifically recommends cleaning and rebuilding for this error; inherited forms and controls must have a successfully built base project before the designer can load them.^1^

    If rebuilding does not fix it:

    1. Close Visual Studio.
    2. Delete the project’s bin and obj directories.
    3. Reopen the .sln, rebuild, and then open the designer.

    Deleting bin and obj can clear stale design-time output and trigger dependency restoration.^1^

    2. Check for the Visual Studio 2026 session-restore problem

    A matching Visual Studio 2026 issue has been reported where the WinForms designer fails to load base classes after reopening a solution or restoring designer tabs.^2^

    After completing the rebuild above:

    1. Close all designer tabs.
    2. Exit Visual Studio completely.
    3. Reopen Visual Studio and the solution without restoring the designer document.
    4. Build the solution.
    5. Open MainForm from Solution Explorer.

    If this sequence works but the failure returns after a session restore, update Visual Studio 2026 to its latest servicing release and add your occurrence to that Developer Community report.

    3. Verify the project target and reference

    Open the project file and verify that it is still a Windows Forms project targeting the intended framework. A modern .NET WinForms project normally contains equivalent properties such as:

    <PropertyGroup>
      <OutputType>WinExe</OutputType>
      <TargetFramework>net8.0-windows</TargetFramework>
      <UseWindowsForms>true</UseWindowsForms>
    </PropertyGroup>
    

    Use the project’s actual .NET version; do not change frameworks merely to match this example.

    Also check:

    • MainForm still derives from Form:
        public partial class MainForm : Form
      
    • Solution Explorer → Dependencies/References has no warning icons.
    • If MainForm derives from a custom base form, that base form’s project builds and is referenced.
    • The project was opened through its .sln or .csproj, rather than opening MainForm.cs by itself.

    Missing references and unbuilt controls or base classes prevent the designer from resolving their types.^1^

    4. Distinguish a project fault from a VS installation fault

    Create a temporary project using File → New → Project → Windows Forms App, build it, and open its default form:

    • New project works: the issue is confined to the original project’s target framework, references, dependencies, or generated build output.
    • New project also fails: repair the Visual Studio WinForms tooling.

    For the second outcome:

    1. Open Visual Studio Installer.
    2. Select Visual Studio 2026 → Modify.
    3. Ensure .NET desktop development is installed.
    4. Under Individual components, ensure the SDK or targeting pack required by the project is installed.
    5. Apply the changes, update Visual Studio, and retest.

    The .NET desktop development workload supplies the Windows Forms and .NET/.NET Framework development components.^3^ If those components are already installed and a new project still fails, use Visual Studio Installer → More → Repair.


    References

    1. Windows Forms Designer error page
    2. Visual Studio WinForms Designer fails to load base classes on session restore - Developer Community
    3. Visual Studio Community component directory
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

    5 people found this answer helpful.
  2. Marcin Policht 114K Reputation points MVP Volunteer Moderator
    2026-11-26T22:40:28.53+00:00

    The error indicates that Visual Studio 2026 cannot load the Windows Forms base class (System.Windows.Forms.Form) when attempting to open the designer. Since the project worked in Visual Studio 2022, this may be related to differences in the Visual Studio installation, project configuration, .NET targeting packs, or designer compatibility. It does not necessarily indicate a problem with your application code.

    Start by determining whether the project still builds successfully. Try Build > Rebuild Solution. If the application compiles and runs but the designer fails, the problem is more likely related to the designer environment or project configuration than to your form's implementation. If the build also fails, examine the first compilation error because it may identify the underlying issue.

    Next, inspect the project file (.csproj). For a modern .NET Windows Forms application, verify that it has the appropriate Windows target framework and Windows Forms configuration. For example, a .NET 10 project should contain settings similar to these:

    <PropertyGroup>
      <OutputType>WinExe</OutputType>
      <TargetFramework>net10.0-windows</TargetFramework>
      <UseWindowsForms>true</UseWindowsForms>
      <ImplicitUsings>enable</ImplicitUsings>
      <Nullable>enable</Nullable>
    </PropertyGroup>
    

    The target framework should match the version your project actually uses. The important settings are the Windows-specific target framework (the -windows suffix) and UseWindowsForms. If this is an older .NET Framework project, do not apply these settings blindly. Traditional .NET Framework Windows Forms projects use a different project configuration and reference System.Windows.Forms through the framework.

    Also verify that the required Visual Studio components are installed. Open Visual Studio Installer, select Visual Studio 2026, and choose Modify. Confirm that the .NET desktop development workload is installed. Check that the targeting pack and SDK for your project's target framework are also available. A missing targeting pack can prevent Visual Studio from resolving framework references correctly.

    Another possibility is stale build output or cached designer information. Close Visual Studio, delete the project's bin and obj directories, reopen the solution, and rebuild it. If the problem persists, close Visual Studio and clear the solution's hidden .vs directory as well. Visual Studio will recreate these files when the solution is reopened.

    Finally, check the form's class definition and its associated designer file. Your MainForm.cs should contain a class declaration similar to:

    public partial class MainForm : Form
    

    The MainForm.cs and MainForm.Designer.cs files must use the same namespace and partial class name. Also verify that the designer file has not been modified in a way that introduces references to unavailable controls, assemblies, or types.

    One additional consideration - if the project uses third-party controls or custom controls, verify that their assemblies are compatible with the target framework and available to Visual Studio 2026. A control that cannot be loaded at design time can sometimes prevent the entire form designer from opening.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    Was this answer helpful?

    4 people found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.