我正在将一个大型网站项目从 Visual Studio 2010 升级到 2012。在我的整个项目中,我都有具有该属性table
的元素。runat="server"
其中许多都包含其中的thead
元素。当我在 2012 年打开它并尝试构建时,我收到以下错误:
Value of type 'System.Web.UI.HtmlControls.HtmlGenericControl' cannot be converted to 'System.Web.UI.HtmlControls.HtmlTableRow'
删除runat="server"
属性或注释掉thead
它会修复它。仅注释掉其中的tr
元素thead
并不能修复它。这是一个重现问题的简化示例:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="Example" runat="server">
<thead>
<tr>
<th>test</th>
</tr>
</thead>
</table>
</div>
</form>
</body>
</html>
错误发生在table
元素打开的地方。
如何在不执行以下操作之一的情况下解决此问题?
- 删除
runat="server"
属性 - 移除
thead
元素 - 将其更改为
asp:table
元素
对解释 2012 年的不同做法导致此问题的人进行额外投票。
更新:
该问题不会出现在 Web应用程序中,只会出现在网站中。
该项目实际上并没有升级,只是我的开发环境。在这两种情况下,我都使用 4.0 框架
我尝试使用 4.5 框架,但没有帮助。
2012 年 9 月 10 日:我有一个 Microsoft 支持的未决案例。他们的开发团队正在研究它。
2012 年 10 月 24 日:由于 .NET 4.5 取代了 4.0,我也无法再在 VS 2010 中编译。我遇到的问题纯粹是 .NET - 而不是 Visual Studio。