ASP.NET Designer.xx生成“已包含定义"控件错误 [英] ASP.NET Designer.xx generates 'already contains a definition for' control error

查看:75
本文介绍了ASP.NET Designer.xx生成“已包含定义"控件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个用于DotNetNuke模块的项目设置.在这个项目中,我有一些用户控制文件,这些文件使用ASP.NET 4.0和C#与TFS一起版本化.

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#.

当前,该项目将顺利构建并正常运行.但是,我对项目中用户控件的某些前端.ascx文件所做的任何更改都会导致相应的.ascx.designer.cs生成约14个错误,指出以下错误:

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:

错误##类型"ControlClass"已经包含"SomeControlID","ControlName.ascx.designer.cs的位置"的定义

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.

我尝试了以下操作:

  • 删除.ascx.designer.cs =>选择项目=>转换为Web应用程序"以重新生成设计器文件.这总是导致显示相同的错误.
  • 重置IIS.删除ASP.NET临时文件.手动清洁溶液并重建.这也会重现相同的错误.
  • 从项目中删除用户控件.添加具有相同名称的新用户控件.建造.将代码复制到新控件的前面和后面.然后重建.重现相同的错误.

为了使事情变得更怪异,当我尝试确定这是否可能是某种语法问题时,我执行了以下操作并产生了以下结果:

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. 撤消所有更改,并在TFS中恢复为工作版本.
  2. 构建项目.没有错误,一切都很好并且可以构建.
  3. 在前端.ascx文件的末尾添加一个空格.
  4. 构建项目.所有错误再次再现.
  5. 确定未执行任何操作后,请按CTRL + Z以确保它没有执行任何操作恢复正常.
  6. 重建项目.所有错误再次再现.

我不确定为什么,但是每次该项目对一些选定的用户控件进行更改时,设计器文件都会突然产生这些错误.

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.

有什么建议吗?

建议我只是手动删除额外生成的控件,以便构建项目.在更深入地研究了这一点之后,我对此有了两个问题.

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.

首先,这将允许项目进行构建,但是每次更新ASCX时,我都必须这样做,因为在删除它们并进行其他更改之后,控件声明又回来了.

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:

基类包含字段'btnDelete',但是其类型(System.Web.UI.WebControls.ImageButton)与控件的类型(Telerik.Web.UI.RadButton)不兼容.

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).

此错误向我表明,我为测试此控件而删除的"btnDelete"控件在构建时被标记为重复"错误,现在被标记为错误类型.

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.

我相信这是由于以下事实:用户控件上存在多个不同类型的"btnDelete"按钮,这给了我错误.这些按钮包含在其编辑/删除模板的不同RadGrid控件中.

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.

推荐答案

想为我添加此错误以及如何解决此问题.

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

发生了一个旧项目,该项目已升级到Visual Studio 2010项目.就我而言,必须将.aspx文件转换为"Web应用程序"以生成设计器文件.在这种情况下,不太确定具体发生了什么,但是开始遇到上述错误.开始查看该变量,但在(.cs),aspx页面或任何其他相关控件后面的代码中没有多次定义它.

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.

我开始查看aspx页面标题,也就是当我注意到可能的问题时.我有2个名称相似的文件... iABC.aspx(.cs,.designer)和ABC.aspx(.cs,.designer),在iABC.aspx标头中,它继承了"ABC" ...第一个符号有些不对劲.我将其更改为正确的设置"iABC",然后决定检查后面代码中的类名,瞧瞧,iABC.aspx.cs的类名设置为"ABC类",而不是"iABC类"

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

戴夫

这篇关于ASP.NET Designer.xx生成“已包含定义"控件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆