The designer could not be shown for this file because none of the classes within it can be designed

Viewed 96706

We have the following shared component:

public class OurServiceBase : System.ServiceProcess.ServiceBase

This class has functionality we want in all our downstream services, such as standardized execution scheduling and logging functionality.

In a new project, I add the following:

public class MyService : System.ServiceProcess.ServiceBase

In the Windows Designer, the class shows properly.

When I change the service to derive from OurServiceBase

public class MyService : OurSharedLibrary.OurServiceBase

The designer stops working:

Error screenshot

The full error is: 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: EmailProcessor --- The base class 'OurSharedLibrary.CienaServiceBase' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.

The proper assemblies are referenced, the project builds. I don't understand why the designer is flipping out over this since my service ultimately does derive from a designable class.

Any suggestions would be most welcome.

Bit more information - the call stack from the designer when it renders the error about not being able to design the derived service:

at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host) 

7/19/2011 2:34PM EDT New discovery.

Class "OurServiceBase" exists in a separate project (usually referenced as a DLL only). On a whim, I copied the base class file into my project, built, and opened the designer. It worked! When I removed the base class file again and returned to the external DLL reference, the designer broke again.

19 Answers

Here's another possible solution:

Under the project properties under build, my platform target was set to x64. I updated this to "Any CPU", rebuilt my project and the designers opened fine.

This explains it better: Visual studio designer in x64 doesn't work

  1. Open "Designer.cs" file
  2. Cut all code and save file
  3. Paste all code and save file
  4. Re-open form / Restart Project / Restart Visual studio (whichever works)

This will do the trick

For me, with VS2022 Version 17.1.1 The fix was to right click an MDI tab and select Close All Tabs

I just closed all the UI pages and cleaned my solution and build it again it started working.

I had this problem in a solution with several projects. I looked at all the projects compile tab, Target CPU. One project was set to x64 all the rest were AnyCPU. I made all the projects Target CPU = AnyCPU, Cleaned Solution, and Rebuilt Solution. Then I could view the form in designer mode.

You can also have this error if your form is in a shared project. The workaround is to exclude the file from the shared project, then create links to the file in the main projects.

I just had the same issue migrating from Visual Studio 2019 to Visual Studio 2022. All worked OK in 2019, designer failing in 2022.

In my case the projects were being build to target x86. Changed all projects with this setting to target Any CPU and that fixed it.

 form1.designer.cs // was showing this
           this.Components = new System.ComponentModel.Container();
           this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
   `enter code here`        this.ClientSize = new System.Drawing.Size(800, 450);
            this.Text = "form1";
  //  I had to add this to the code to get it to work
   this.Name = "form1";
   this.ResumeLayout(false);
   this.PerformLayout();

Further to Ausibanez's answer above.

My app was in X64 but my problem was I had recently added a COM reference to WIA (Windows Image Acquisition) which was the issue.

But oddly...

  1. It worked for some time before it decided to no longer work, and
  2. WIA was not being called on the particular inherited form or its base.

But, once the reference to WIA was removed, all was OK again.

So, check your COM references!

  1. Go to Project>>Properties>>Linker>>System, in the field "SubSystem" you choose "Windows (/SUBSYSTEM:WINDOWS)", click Apply.

  2. Go to Project>>Properties>>Linker>>Advanced, in the field "entry point", input value "Main" and Apply, finally click OK.

  3. Go to file code of form you created(ex: MyForm.cpp) and input code bellow to this file:

using namespace System;

using namespace System::Windows::Forms;

[STAThreadAttribute]

void Main(array<String^>^ args)

{

Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); Project1::MyForm form; Application::Run(%form);

}

  1. Save and rebuild.

My workaround was to remove the reference to System.Windows.Forms, and then add it back in again.

This is on a C++/CLI project, on .NET Framework 2.0.

Had a similar issue, exiting out and reloading visual studio seemed to fix the issue

Just got the same issue using VS2019 (+ framework 4.7.2)

However, simply deleting the .vs hidden directory from the solution directory was enough. This folder is some sort of cache, and this files it contains can get corrupted and would need to be rebuild.

Note: this will delete all you breakpoints though

Go this hint from here.

... and also from @Goodies and @Tim (afterwards!) who also mentioned it in small print comments in this page. I worth posting it as an "Answer".

I had this issue with a WinForms .NET framework project from 2016 that I developed with VS 2015. I opened it with VS 2022 and the error appeared. After downgrading the project from .NET 4.7.1 to 3.5, then back to 4.7.1, everything worked fine.

Related