C# Winforms Designer won't open because it cannot find type in same assembly

Jonathan Beerhalter picture Jonathan Beerhalter · Apr 5, 2013 · Viewed 9k times · Source

I'm getting the following error

Could not find type 'My.Special.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.

But what doesn't make any sense is that My.Special.UserControl is in the same assembly as the form. What's more, if I view code on the Designer.cs file, There are references to My.Special.UserControl that seem to be fine. The assembly builds fine, and runs fine as well. It's the just the designer that's having issues.

As such we have to do all our design work by making adjustments to the Designer.cs file by hand. How can I make the designer work again?

Answer

CarlC picture CarlC · Mar 25, 2015

The following procedure has worked for me:

  1. Delete the /bin and /obj folders in your source code directory.
  2. Restart VS (be sure the offending Form Designer is closed)
  3. Compile
  4. Open the Form in Designer again. The problem should be resolved.

I'm sure deleting both /bin and /obj are not necessary, but I haven't been able to reproduce the error and come to a more specific solution. (My projects are typically small enough that re-compiling the whole thing is no big deal.)

Usually, this error seems to occur after refactoring / renaming objects of the offending class. So my guess is that there is a VS bug that doesn't recompile the appropriate object file after a User Control or Custom Control is refactored.