Saturday, 15 November 2014

Visual Studio Designer Errors - Could not find type 'CONTROL NAME HERE'. Please make sure that the assembly that contains this type is referenced


Problem
When working with visual development projects in Visual Studio (Can occur in WinForms and WPF applications!), you may encounter a Designer/XAML error such as the following:

To prevent possible data loss before loading the designer, the following errors must be resolved:

Could not find type 'CONTROL NAME HERE'. 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.

The variable 'CONTROL NAME HERE' is either undeclared or was never assigned.

When these errors occur, typically you may have an error within your application. Simply fix the error, rebuild your solution, and the designer error will disappear! However.... this may not always be the case!

Who What Where Why
In Win Forms applications, Visual Studio keeps a designer file for each Form class within your application. This details where components are laid out of the form, their events, text values and more! (Basically all of their properties). Sometimes, these designer files get a little confused and they cannot sync properly with what the form contains as it's all done automatically behind the scenes. This can happen a lot when using User Controls as the project needs to be built successfully in order for the form to consume the control! (These designer errors may typically reference a User Control a lot of the time).

Resolution
If there are no errors within your application and this error appears, DO NOT EDIT THE DESIGNER FILE! (Never do this for that matter!), Visual Studio should always handle this task. Simply, re-build the whole solution, then restart Visual Studio.

No comments: