vb.net ASP.Net 错误 - 类型与控件类型不兼容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19502307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:34:15  来源:igfitidea点击:

ASP.Net error - type is not compatible with the type of control

asp.net.netvb.netvisual-studio-2012runatserver

提问by Matan L

I have a web site i created using VS2012 web edition,

我有一个使用 VS2012 网络版创建的网站,

Running a VB.net asp web site,

运行一个 VB.net asp 网站,

In the VS2012 debug/release mode it compiles and everything works good, When i upload it to a server (Windows server 2008 R2) I get the following error:

在 VS2012 调试/发布模式下,它编译并且一切正常,当我将它上传到服务器(Windows server 2008 R2)时,出现以下错误:

The base class includes the field 'html', but its type (System.Web.UI.HtmlControls.HtmlElement) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlGenericControl).


Line 2:  
Line 3:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Line 4:  <html id="html" xmlns="http://www.w3.org/1999/xhtml" dir="ltr" runat="server">
Line 5:  <head id="Head1" runat="server">
Line 6:    <title></title>

I looked a bit on the web and found this : VS 2010: Value of type 'System.Web.UI.HtmlControls.HtmlGenericControl' cannot be converted to 'System.Web.UI.HtmlControls.HtmlTableRow'

我在网上查了一下,发现这个: VS 2010:类型'System.Web.UI.HtmlControls.HtmlGenericControl'的值不能转换为'System.Web.UI.HtmlControls.HtmlTableRow'

Installed it but no help,

安装了但是没有用

The site i created was re-created from another vb.net project so i used a web.config with from the old one, maybe it has something to do with it, i have no "assembly" properties it this XML.

我创建的站点是从另一个 vb.net 项目重新创建的,所以我使用了旧的 web.config,也许它与它有关,我没有这个 XML 的“程序集”属性。

Other pages that are not related to that master page (that html tag is running on a master page...) work's fine.

与该母版页无关的其他页面(该 html 标记在母版页上运行......)工作正常。

采纳答案by Matan L

OK,

好的,

So after trying a lot of stuff that didnt work i found a solution, i dont like this solution but it works,

所以在尝试了很多不起作用的东西后,我找到了一个解决方案,我不喜欢这个解决方案,但它有效,

I went to the page.designer.vbfile, and then looked for the 'html' and 'Head1' properties that were generated there,

我转到page.designer.vb文件,然后查找在那里生成的“html”和“Head1”属性,

In there i replaced their types to System.Web.UI.HtmlControls.HtmlGenericControl

在那里,我将它们的类型替换为 System.Web.UI.HtmlControls.HtmlGenericControl

Afterwards, it worked.

后来,它奏效了。

Weird bug, nothing else (including the "hot fixes" that are mentioned in other posts helped.

奇怪的错误,没有别的(包括其他帖子中提到的“热修复”)有帮助。

Hope this would help some one out there .

希望这会帮助一些人那里。

回答by taylorsabell

Somehow the designer file and the markup file get out of sync, even if the types appear to match.

不知何故,设计器文件和标记文件不同步,即使类型看起来匹配。

I changed the ID attribute of the problematic control, saved, and rebuilt in the markup file. I then changed it back to the original ID, saved, and rebuilt.

我更改了有问题的控件的 ID 属性,保存并在标记文件中重建。然后我将其改回原始 ID,保存并重建。

Problem goes away!

问题迎刃而解!

回答by Jamshaid Kamran

Weird issue it is I am not sure if there is a proper solution for this but what worked for me was simply changing the Control ID. and then designer.cs file was changed and all worked good.

奇怪的问题是我不确定是否有适当的解决方案,但对我有用的只是更改Control ID。然后designer.cs 文件被更改并且一切正常。