72

We have recently upgraded all of our WebForms projects to .NET 4.5, and encountered a parser issue when loading pages with an iFrame element. We have corrected this by converting of the iFrame from HtmlGenericControl to HtmlIframe. This has corrected all of the parser errors when we run our code locally.

When we deploy the app, we get the following error message:

Parser Error Message: 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).**

When I deploy the old code with the HtmlGenericControl the error goes away suggesting that even though we have installed .NET 4.5, the server is still using an older version?

I've tried removing and reinstalling .NET it making sure to register asp with IIS.

Windows 2008 R2 with IIS 7.5 and .NET 4.5

11 Answers 11

91

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.

7
  • Do you know if <pages controlRenderingCompatibilityVersion="4.0" might as also be causing this issue?
    – crush
    Sep 15, 2014 at 15:24
  • In my experiments, <pages controlRenderingCompatibilityVersion="4.0" /> does not affect how the ASP.NET compiler parses an <iframe runat="server" /> control if <compilation targetFramework="4.5"/> is set. Sep 16, 2014 at 3:11
  • 15
    +1 for this sentence: "You can do this by re-saving the Web Forms HTML file which will cause the designer file to be regenerated." That was the fix for us. Dec 2, 2015 at 13:56
  • @JamesQMurphy Thanks! Dec 3, 2015 at 2:07
  • 3
    Excellent response. Re-saving the aspx file worked perfectly.
    – cowsay
    Mar 29, 2016 at 14:49
34

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.

3
  • Thanks for the input as you can, see from the accepted answer above, the issue was fixed some time ago now.
    – gambisk
    Nov 27, 2013 at 14:38
  • 3
    After upgrading a .NET 3.5 project to 4.5 I was missing the asp tagPrefix under controls that avoided a Unknown server tag 'asp:HtmlIframe'. Parser error. Jan 24, 2014 at 0:55
  • Are there any other controls that have a breaking change like this? Sep 16, 2014 at 15:48
20

We were able to fix the issue converting the

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

to

<asp:HtmlIframe id="iframe" runat="server" />
2
  • 7
    Answer doesn't mention you must add namespace 'System.Web.UI.HtmlControls' to Web.config. (See Panoj for complete answer). Aug 20, 2014 at 11:53
  • 1
    Or add the namespace in the specific aspx file. Feb 1, 2016 at 9:17
7

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.

2
  • 1
    Thanks! I had inadvertently removed the targetFramework="4.5" in my compilation node to troubleshoot a production error, and then started getting this error on my localhost. This answer saved me :)
    – Shiva
    Sep 12, 2016 at 19:03
6

You can keep your HTML element as <iframe>, and simply modify your .designer file to change the type to

System.Web.UI.HtmlControls.HtmlIframe
1
  • 3
    It seems it gets reverted back upon saving the .ASPX files.
    – Uwe Keim
    Aug 15, 2014 at 14:37
3

Further (or in as a combination of the answers here).

I don't believe it's needed to actually change the tags from iframe to asp:HtmlIFrame if you have the reference to the updated System.Web.UI.HtmlControls.

I updated my web.config to remove specific versions of the tag prefix and replace it with:

<add tagPrefix="asp" namespace="System.Web.UI.HtmlControls" assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

Clean and rebuild the project and that regenerates all the designer tags for me with the correct HtmlIFrame output.

2

i had also face this issue but simply i deleted this UserControl ans added new userControl with same name then my issue were fixed.....

  <iframe id="logPanel" runat="server" scrolling="auto" src="">

0

Look into designer file, and replace Htmliframe for HtmlGenericControl in the control that has problems.

1
  • You mean the other way around, replace HtmlGenericControl with Htmliframe. Feb 1, 2016 at 9:17
0

From .NET 4.5, Microsoft decided to change the iframe from a HtmlGenericControl to its own control, a HtmlIframe. so you have to change the

System.Web.UI.HtmlControls.HtmlGenericControls to System.Web.UI.HtmlControls.HtmlIframe
0

What worked for me was the following

  • removing/commenting out the frame.

  • compiling/running the application.

  • adding/uncommenting the frame.

  • running the application again.

the line in the designer.cs file was automagically changed from

protected global::System.Web.UI.HtmlControls.HtmlGenericControl fPdf;

to

protected global::System.Web.UI.HtmlControls.HtmlIframe fPdf;

-1

My solution was to just rename the IFrame and rebuild and the designer file will be updated accordingly with the correct references.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.