In a certain solution (i.e., .sln
) I have, something seems to confuse Designer. I am using visualstudio-17.0.4. I get the following error:
Could not find type ‘System.Windows.Forms.UserControl’. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU.
Note that the type in question is System.Windows.Forms.UserControl
, a framework provided type not a type from my development project. I am referencing System.Windows.Forms
and targeting .net-4.6 and AnyCPU. The project builds fine without any errors and even IntelliSense knows about the type. Designer might be trying to load dependencies in a different way than IntelliSense does. But it does not give me enough information to figure out why it is failing.
All of the normal resolutions did not work for me. However, I noticed that Designer would load sometimes. After further experimentation, I found that Designer would load if I tried to open it within a project which had no open editor windows when I opened the solution as long as I attempted to open Designer in a different project first. Note that simply unloading and reloading a project or closing all windows without restarting visualstudio is not enough. Follow these steps strictly if you are experiencing the same issue as me.
- Open your Solution in Visual Studio.
- Right-click on a project containing winforms Designer files and select Unload Project (L) OR close all windows using the menu action Window / Close All Tabs (M-w l).
- Exit Visual Studio.
- Open your Solution in Visual Studio.
- Try opening Designer on a file in a different project. It should fail to load.
- If you had unloaded the project earlier, right-click on the unloaded project and select Reload Project (L).
- Right-click on the project and select Rebuild.
- If you have run Rebuild on multiple projects, be sure to later select all projects and select Build.
- Double click (enter) on a winforms Designer file in that project. The Designer should successfully load.
If you need to edit winforms Designer files in multiple projects, you may need to unload and then load/build multiple projects instead of the single project.
This solution is temporary. If you close Visual Studio without unloading your projects container winforms Designer files first, you will no longer be able to open those winforms Designer files until you follow the procedure again.
If you do not use 100% DPI, you may want to replace steps 3 and 4 with restarting Visual Studio in 100% DPI mode. Note that these steps only work if you did not yet open any winforms Designer files (the 100% prompt only shows up for the first winforms Designer file you open):
In a different project, double click on a winforms Designer file. It may fail to load, but if this is the first winforms Designer file you opened in this Visual Studio session, you should get a prompt:
Scaling on your main display is set to 175%. Restart Visual Studio with 100% scaling Help me decide.
Choose the “Restart Visual Studio with 100% scaling” option.
See also: an explanation of ProjectAssemblies (archive). When experimenting, I found that VisualStudio loaded and cached an old version of assemblies, so if you are updating the controls used by your designable control, you cannot escape from needing to restart VisualStudio sometimes.