Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Designer.xx generates 'already contains a definition for' control error

Tags:

c#

asp.net

I currently have a project setup for a DotNetNuke module. Within this project I have some user control files, which are versioned with TFS using ASP.NET 4.0 and C#.

Currently, the project will build and run fine with no issues. However, ANY change I make to the front end .ascx files of SOME of the user controls in the project will cause the corresponding .ascx.designer.cs to generate ~14 errors stating the following error:

Error ## The type 'ControlClass' already contains a definition for 'SomeControlID' 'Location of ControlName.ascx.designer.cs'

I have not made any other changes to this previously that I could think of that would cause this issues. It just randomly started happening in my project.

I have tried the following:

  • Delete .ascx.designer.cs => Choose project => 'Convert to Web Application' to regenerate the designer file. This always results in the same errors being displayed.
  • Reset IIS. Delete ASP.NET Temporary files. Manually clean solution and rebuild. This also reproduces the same errors.
  • Delete user control from project. Add new user control with same name. Build. Copy in code to new control front and back. Then rebuild. Reproduces the same errors.

To make things weirder, when I tried to determine if this could be some sort of syntax issue I did the following and produced these results:

  1. Undo all changes and revert back to working version in TFS.
  2. Build the project. No errors everything is fine and builds.
  3. Add a space to the end of the front end .ascx file.
  4. Build the project. All errors reproduced again.
  5. Upon determining that did nothing, hit CTRL+Z just to make sure it is back to normal.
  6. Rebuild the project. All errors reproduced again.

I am not sure why, but every time this project has a change to a few select user controls, the designer files generate with these errors all of a sudden.

These user controls contain complex controls which contain templates full of other controls, etc... However when building these I had no issues with names being the same in different templates and things like that.

I have run out of ideas and have found nothing else to try by searching this issue online.

Any suggestions??

EDIT: It has been suggested that I just manually delete the extra generated controls so that the project will build. After looking into this more deeply I have two issues with this.

First, this will allow the project to build, but I would have to do this EVERY time I update the ASCX, as after I delete them and make another change the control declarations are back.

Second, while this will allow the project to build without issue. It does not run but instead throws the following runtime error:

The base class includes the field 'btnDelete', but its type (System.Web.UI.WebControls.ImageButton) is not compatible with the type of control (Telerik.Web.UI.RadButton).

This error indicates to me that the 'btnDelete' control that I deleted to test this, which was marked as a 'duplicate' error when building is now marked as the incorrect type.

This I believe is due to the fact that there are multiple 'btnDelete' buttons of different types on the user control that is giving me the error. These buttons are contained within different RadGrid controls for their edit/delete templates.

like image 407
user1048281 Avatar asked Nov 12 '22 22:11

user1048281


1 Answers

Want to add in my case for this error and how I solved.

Happened with a legacy project that was being upgraded to visual studio 2010 project. In my case had to convert the .aspx files to "Web Applications" for the generation of designer files. In this case, not too sure on specifically what happened but started to get the error mentioned above. Started looking at the variable but it was not defined more than once in the code behind (.cs), aspx page or any other associated controls.

I started to look at the aspx page headers and that is when I noticed the possible problem. I had 2 files with similar names... iABC.aspx (.cs,.designer) and ABC.aspx(.cs,.designer) and in the iABC.aspx header, it was inheriting "ABC"...first sign something was amiss. I changed it to the correct setting "iABC" and then decided to check the class name in the code behind, lo and behold, the class name for the iABC.aspx.cs was set to "class ABC" instead of "class iABC".

Once I fixed up the mess, all was good.

HTH

Dave

like image 198
Dave Avatar answered Nov 14 '22 22:11

Dave