19

I'm upgrading a big web site project from Visual Studio 2010 to 2012. Throughout my project, I have table elements with the runat="server" attribute. Many of these have thead elements inside of them. When I open it in 2012 and and try to build, I get the following error:

Value of type 'System.Web.UI.HtmlControls.HtmlGenericControl' cannot be converted to 'System.Web.UI.HtmlControls.HtmlTableRow'

Removing the runat="server" attribute or commenting out thead fixes it. Commenting out only the tr element inside of thead does not fix it. Here is a simplified example that reproduces the problem:

<%@ 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>

The error occurs where the table element opens.

How can I fix this without doing one of the following?

  • Removing the runat="server" attribute
  • Removing the thead element
  • Changing it to an asp:table element

Bonus up vote for someone who explains what 2012 is doing differently that is causing this.

UPDATE:

The problem does not occur in a web app, only in a web site.

The project isn't actually be upgraded, just my development environment. In both cases, I'm using the 4.0 framework

I tried using the 4.5 framework, but it didn't help.

Sept 10th, 2012: I have an open case with Microsoft support. Their dev team is looking into it.

Oct. 24, 2012: Since .NET 4.5 replaces 4.0, I can no longer compile in VS 2010 also. The problem I am experiencing is purely .NET - not Visual Studio.

Keith Walton
  • 4,849
  • 5
  • 35
  • 53
  • I don't get this error. I copied your code as is. I'm using 2012 RC. – Amiram Korach Aug 27 '12 at 20:18
  • My version is 11.0.50727.1 RTMREL. Can you try the following? 1. File|New|Web Site. 2. Visual Basic|ASP.Net Empty Web Site. 3. Web Site|Add New Item 4. Web Form - name it test.aspx. 5. Paste in markup. 6. Build|Build Web Site. – Keith Walton Aug 27 '12 at 20:25
  • 1
    I just tested a web app, and it worked. The problem appears to be specific to a web site. – Keith Walton Aug 27 '12 at 20:30
  • I tested it exactly like that in the first place – Amiram Korach Aug 27 '12 at 21:32
  • Does the error message indicate what line of the markup it relates to? – JK. Aug 29 '12 at 21:38
  • @JK. It's the line where the table element opens. – Keith Walton Aug 29 '12 at 21:45
  • 2
    Not sure what's going on. Note even though you get an error in VS, the page actually compiles and runs fine if you run it. So it looks like an issue specific to how the code gets generated in VS. You don't see this in Web Apps because views are not compiled at all in VS by default. – David Ebbo Aug 30 '12 at 00:09
  • 1
    Can you explain why you need the server tag? Jusdging from this question, it just used to remove the `` tag. http://stackoverflow.com/questions/2877898/asp-net-listview-render-thead-tbody-tags If it's displaying an error now instead of silently removing the tag, I'd consider that an *improvement*. – Kevin Stricker Aug 30 '12 at 01:32
  • @mootinator Interesting. I'll check and see if that is the behavior in 2010. If so, I'll just delete the thead elements. – Keith Walton Aug 30 '12 at 21:34
  • @mootinator VS 2010 is not removing thead in my case. I use the server tag to show/hide the tables, and to iterate through server controls within it. I could do it another way, but I'm trying to find an easy copy/paste solution to update a lot of code doing this. – Keith Walton Aug 30 '12 at 22:18
  • When you say "upgrading from 2010 to 2012" are you saying you're upgrading the site from targetting Framework 2.0 to 4.5? Im wondering whether this is a framework targeting problem - that being in 2010 its targetting 2.0 and in 2012 somehow its switched to targetting 4.5 auto-magically? if thats the case try changing your target framework back to 2.0 and see if the issue persists? – Luke Baughan Aug 31 '12 at 15:57
  • @bUKaneer By upgrading I mean just my development environment. The project is not changing - it is still targeting 4.0 via the web.config file. – Keith Walton Sep 04 '12 at 17:31

6 Answers6

4

Fix for this issue is available now. http://support.microsoft.com/kb/2750149 for windows 8 and http://support.microsoft.com/kb/2750147 for Windows 7 platform.

Anand
  • 1,440
  • 8
  • 11
3

Microsoft has confirmed this is a bug. They will create a hot fix for it, and include the fix in the next service pack. It doesn't sound like this is a high priority, so it will probably take a while for the hot fix.

2012-10-01 Update: Microsoft support contacted me and said this will be fixed in an upcoming hot fix "soon".

2012-11-28 Update: Visual Studio 2012 Update 1 does not fix the problem.

Keith Walton
  • 4,849
  • 5
  • 35
  • 53
  • That's really interesting - great question, great answer! – Luke Baughan Sep 13 '12 at 16:25
  • Do you have the details of this bug report Keith? – Dai Bok Sep 17 '12 at 13:47
  • Microsoft has not provided it to me yet. I left my case open with instructions to give me the number associated with the fix. If you are experiencing this problem, be sure to let them know. The more people who report it, the sooner it gets fixed. You can refer them to this page in your support request. – Keith Walton Sep 18 '12 at 14:32
  • Where's the report link? I say this because I've inherited an app that has this issue *everywhere* and VS2012 is not happy. – Ted Dec 10 '12 at 23:44
  • And ditto for VS2010 as you found out. No joy for this Win8 VM so back to the Win7 VM for this app's development. Fortunately my dev environments are virtualized or else this would be even more problematic. – Ted Dec 11 '12 at 00:00
  • 1
    @KeithWalton and here I was hoping you'd have a report link that I could click on and go "me too!" I'm assuming you have one somewhere? In the meantime I created one myself at https://connect.microsoft.com/VisualStudio/feedback/details/774181/table-tag-with-runat-server-causes-build-exception-value-of-type-system-web-ui-htmlcontrols-htmlgenericcontrol-cannot-be-converted-to-system-web-ui-htmlcontrols-htmltablerow – Ted Dec 13 '12 at 02:13
  • @KeithWalton, This is regarding comment in your answer "2012-10-01 Update: Microsoft support contacted me and said this will be fixed in an upcoming hot fix "soon".". Can you please provide details on whom did you talk to from Microsoft support side? I will appreciate if you can send this info by emailing to netfx45compat@microsoft.com. – Anand Dec 13 '12 at 20:14
  • @Ted It was a Microsoft Support case (112090472486571). Unfortunately, I don't think you can "me too" one of those. – Keith Walton Dec 13 '12 at 23:39
  • @Anand I will forward you the latest email I received from him. Most of our conversations were over the phone. – Keith Walton Dec 13 '12 at 23:40
  • You can "me too" at http://connect.microsoft.com/VisualStudio/feedback/details/766115/value-of-type-system-web-ui-htmlcontrols-htmlgenericcontrol-cannot-be-converted-to-system-web-ui-htmlcontrols-htmltablerow – Ted Jan 07 '13 at 17:58
  • 1
    Posted by Microsoft on 12/30/2012 at 11:27 PM ...this fix will be available in couple of weeks via windows update. – Ted Jan 07 '13 at 18:00
  • 1
    Apparently it has arrived: http://support.microsoft.com/kb/2750147 although I haven't tried it out yet. – Ted Jan 22 '13 at 17:41
3

For partial solution you can move that <th> front-end code to the back-end code. That should take care of the compilation problem. Don't know what to do about <tbody> tags though. If you view HTML of your page as it stands now, I doubt that they render anyway. Here is why.

Community
  • 1
  • 1
1

Simple solution remove tags tbody and thead, for me worked.

longneck
  • 11,077
  • 2
  • 34
  • 43
-1

I don't have VS 2012; right now but you should try following things

  1. Can you verify changing DOCTYPE. (to transitional, frame-set, 1.1 or html 5 etc)
  2. Put the whole table inside asp:placeholder
Subodh Patil
  • 82
  • 1
  • 9
-1

Yes Its a bug in Visual Studio 2012,Applying the patch from below mentioned link has worked for me: http://www.microsoft.com/en-us/download/details.aspx?id=36359

Removing the tag won't solve it out for a current/migrating running project. In that way we have to change each and every aspx page.

Ankur Bhutani
  • 2,657
  • 3
  • 26
  • 25