Element ‘X’ is not a known element – Web Application

I converted a forms website into an application and everything has been working just fine until now. I keep getting the green squiggly lines and the error that Element ‘X’ is not a known element. This is on almost every element, Gridview, Label, Update Panel, Hyperlink Field, Bound Field, etc…

my web.config contains

<pages theme="basic">
        <controls>
            <add tagPrefix="ajax" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit"/>
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </controls>
    </pages>

so ajax and asp are viable prefixes. The very odd thing is that it is only happening on a few user controls, all other user controls are fine and the errors never show up. I have tried rebooting and everything and nothing seems to fix it. All masterpages, web paages, and about 90% of the user controls are fine, its only on a few user controls and super annoying!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If the compilation element in your web.config file has the targetFramework="4.0" attribute, I don’t think the references to the System.Web.Extensions assembly are required anymore. If you look at the root-level web.config file at %WINDIR%Microsoft.NETFrameworkv4.0.30319Config, you will notice that the following lines are already in the <controls> section of the web.config file:

<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls.Expressions" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

The System.Web.Extensions assembly is also referenced in the <compilation><assemblies> section
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

and the following <httpHandlers> are added as well
<add verb="*" path="*_AppService.axd" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="False" />
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="False"/>
<add path="*.asmx" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="False" />

Additionally, the following <httpModules> are registered by default
<add name="ScriptModule-4.0" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

In short, your web.config file probably should not contain any references to the System.Web.Extensions assembly because it is already referenced in almost every conceivable way in the root-level web.config file.

Additional References: How to: Upgrade an ASP.NET Web Application to ASP.NET 4

Method 2

I think this is a bug in Visual Studio. When I run into this I would try to select all in the aspx page, cut, then paste it right back where it was. Then the controls should be added to the designer file. If that doesn’t work, delete the designer file and try to convert it to a web app again. Good luck! I would also like to know if there is a better solution.

Method 3

I faced the same error and it turn out to be case sensitive issue with CodeBehind attribute in control declaration at first line.

Following was giving the problem

<%@ Control Language="C#" AutoEventWireup="true" Inherits="ContactListControl" Codebehind="ContactListControl.ascx.cs" %>

Mostly changing it to – resolve the problem
<%@ Control Language="C#" AutoEventWireup="true" Inherits="ContactListControl" CodeBehind="ContactListControl.ascx.cs" %>

I suggest using Visual Studio auto formatting feature (shortcut ctrl+k+d), it take care of such capitalization/formatting issues.

Method 4

I had the exact same problem and I tried everything until I deleted my suo file, then the problem disappeared


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x