Occasionally, a C# project will have a user control in it that belongs to another C# project and I will have to move it over. Attempting to simply copy + paste that user control over results in namespace errors. Let's say project 1 has a namespace of namespace General.Category1.Controls
and project 2 has a namespace of namespace General.Category2.Controls
.
The steps I initially took were:
1) Copy + paste control (which includes .cs
, designer.cs
and .resx
files) from project 1 to project 2
2) Change namespace to project 2's namespace General.Category2.Controls
At this point upon building, I received additional errors from the forms on which this control is used before the copy + paste that states 'The type of namespace name 'UserControl1' does not exist in namespace 'General.Category1.Controls' (are you missing an assembly reference?)
. It turns out that the designer.cs
form files did not update to the correct namespace after the copy + paste.
So then I add to add an additional step:
3) Change declarations to match new namespace of General.Category2.controls
aka private General.Category2.Controls UserControl userControl1;
I'm confused why the designer.cs
files wouldn't have updated that since it's not usually advised to edit designer.cs
files. But then again, maybe it's ok to modify them as long as you don't touch the InitializeComponent()
method as it states in the actual file itself.
In conclusion, why do all of the designer.cs
not update automatically? Is the actual answer to know where this control is used and update the declarations myself as I have done?
[EDIT]: The first 2 steps are for the control itself (it's .cs
and .designer.cs
files). The 3rd step is for associated with any forms in which the control was placed on before copying it over because it is still using the old namespace, so all of the form .designer.cs
files must be changed as well.