iFrame parser error after upgrading to .NET 4.5

Check that you have next settings in your config file. Also make sure that it's there after publishing.

<system.web>
    <httpRuntime targetFramework="4.5" />
    <compilation debug="true" targetFramework="4.5"/>
    ...
</system.web>

Hope it's should help.


You need to add the following tag:

<asp:HtmlIframe>

and in the designer, change the control type to:

System.Web.UI.HtmlControls.HtmlIframe

Add the following in the Web.config:

<controls>
 <add tagPrefix="asp" namespace="System.Web.UI.HtmlControls" assembly="System.Web"/>
</controls>

This should fix it.


We were able to fix the issue converting the

<iframe id="iframe" runat="server" />

to

<asp:HtmlIframe id="iframe" runat="server" />

The basic problem is an incompatibility between the object generated from your Web Forms IFRAME server control by the ASP.NET compiler (which compiles ASPX and ASCX files to C# or VB code) and the type of the variable corresponding to that control in your Web Forms code behind. An IFRAME server control (<iframe id="frame" runat="server" />) will be parsed as a control of a particular type. In ASP.NET 4 an IFRAME server control will be an HtmlGenericControl control. In ASP.NET 4.5 an IFRAME server control will be an HtmlIframe control.

The problem can be fixed by making sure that the targetFramework attribute on the compilation element in your web.config file agrees with the Target Framework property of your project and that the variable corresponding to your IFRAME server control matches the type of control the ASP.NET compiler will generate.

An ASP.NET 4 project that has been converted to .NET Framework 4.5 in Visual Studio 2013 will modify the project's web.config file so that targetFramework attribute of the compilation element has a value of "4.5" (<compilation targetFramework="4.5"/>). This causes the ASP.NET compiler to treat the IFRAME server control as a HtmlIframe control. This can cause a problem if the Web Forms code behind control variable is still an HtmlGenericControl. The error you see is like this:

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

The solution to the previous error is to update the type of the server control variable that corresponds to the IFRAME server control. You can do this by re-saving the Web Forms HTML file which will cause the designer file to be regenerated. As far as I can see (in Visual Studio 2013 at least) changing the control ID is not necessary. If the server control variable is in the code behind file, it must be updated manually.

An ASP.NET 4.5 project where the code behind variable is an HtmlIframe will experience a similar but different issue if the targetFramework attribute of the compilation element in the web.config file has a value of "4.0" (<compilation targetFramework="4.0"/>). This causes the ASP.NET compiler to treat the IFRAME server control as a HtmlGenericControl control. The error you see is like this:

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

The way to fix the previous error is to make sure the web.config compilation settings agree with your project's Target Framework attribute. In this case the targetFramework attribute of the compilation element in the web.config should have a value of "4.5".

<compilation targetFramework="4.5"/>


Note: Setting the httpRuntime element's targetFramework attribute to 4.5 will also have the effect of setting the compilation element's targetFramework attribute to 4.5. See https://devblogs.microsoft.com/dotnet/all-about-httpruntime-targetframework/ for more info.

Note 2: There is no <asp:HtmlIframe> tag. Registering the tag prefix "asp" to the System.Web.UI.HtmlControls namespace is not something that is required to use an IFRAME server control.