Why does this compile in 3.5, but not 4?http://forums.asp.net/t/1524761.aspx/1?Why+does+this+compile+in+3+5+but+not+4+Mon, 22 Feb 2010 22:19:13 -050015247613674447http://forums.asp.net/p/1524761/3674447.aspx/1?Why+does+this+compile+in+3+5+but+not+4+Why does this compile in 3.5, but not 4? <p>In 3.5 adding an element in markup and referencing it via a property compiles fine:<br> &lt;link id=&quot;lnkMainIE&quot; runat=&quot;server&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;<br> public HtmlLink StyleMainIE { get { return lnkMainIE; } }<br> <br> In 4, it gives the error <i>Cannot implicitly convert type 'System.Web.UI.HtmlControls.HtmlGenericControl' to 'System.Web.UI.HtmlControls.HtmlLink'</i> <br> If I declare my property as type HtmlGenericControl, I get the parser error at run time, <i>The base class includes the field 'lnkMain', but its type (System.Web.UI.HtmlControls.HtmlGenericControl) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlLink)<br> <br> </i>Something seems amiss...</p> 2010-02-11T17:10:20-05:003674739http://forums.asp.net/p/1524761/3674739.aspx/1?Re+Why+does+this+compile+in+3+5+but+not+4+Re: Why does this compile in 3.5, but not 4? <p>I dont know the technical reason for the difference but it seems like its asking you to use the following format:</p> <p><pre class="prettyprint">&lt;asp:HtmlLink id=&quot;lnkMainIE&quot; runat=&quot;server&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;</pre><br> <br> </p> <ul> <li><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmllink%28VS.100%29.aspx">http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmllink(VS.100).aspx</a><br> </li></ul> 2010-02-11T19:17:57-05:003687795http://forums.asp.net/p/1524761/3687795.aspx/1?Re+Why+does+this+compile+in+3+5+but+not+4+Re: Why does this compile in 3.5, but not 4? <p>It works fine for me in both, 3.5 and 4.0. Are you using VS2010 RC? Do you put the link&nbsp;inside the &lt;head&gt; section?</p> 2010-02-18T18:13:02-05:003693798http://forums.asp.net/p/1524761/3693798.aspx/1?Re+Why+does+this+compile+in+3+5+but+not+4+Re: Why does this compile in 3.5, but not 4? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>anhphan</h4> <p></p> <p>It works fine for me in both, 3.5 and 4.0. Are you using VS2010 RC? Do you put the link&nbsp;inside the &lt;head&gt; section?</p> <p></p> </blockquote> <p></p> <p>I'm placing it in a Content tag that references the head section in the master page.&nbsp; Doesn't compile in either Beta 2 or RC1.<br> </p> 2010-02-22T14:38:17-05:003694430http://forums.asp.net/p/1524761/3694430.aspx/1?Re+Why+does+this+compile+in+3+5+but+not+4+Re: Why does this compile in 3.5, but not 4? <p>does the &lt;head&gt; tag in the masterpage have runat=&quot;server&quot; on it?<br> </p> 2010-02-22T21:12:40-05:003694531http://forums.asp.net/p/1524761/3694531.aspx/1?Re+Why+does+this+compile+in+3+5+but+not+4+Re: Why does this compile in 3.5, but not 4? <p>If you add&nbsp;a link inside the &quot;head&quot; Content in a content page, this link is not a direct child under the&nbsp;&lt;head&gt; tag, but a child of the head &lt;ContentPlaceHolder&gt; tag. You will get an HtmlGenericControl in this case. There is no way to convert this to an HtmlLink. This behavior has been existing since 2.0 AFAIK. You said it compiles in 3.5, did you use VS2008 and see it compile? I see the same behavior for both VS 2008 and VS 2010 for a 3.5 project.</p> 2010-02-22T22:19:13-05:00