views:

80

answers:

2

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!

A: 

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.

Mike
I have found this problem usually indicates subtle errors in markup - such as capitalizing the word true or false when setting a property in markup. On a custom control, the culprit is often misapplication of attributes by people who just like to throw attributes on their classes / properties without having any clue what they do.
Chris Shouts
I tried to copy out everything and re-paste it and that didn't work. The errors are still there. Also when I use the intellisense I do not get some of my asp: controls....
EvanGWatkins
I have also deleted the designer file and re-converted the web app and it is still showing the errors
EvanGWatkins
Nothing seems to be preventing this from happening any other ideas?
EvanGWatkins
+1  A: 

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.NET\Framework\v4.0.30319\Config, 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

Chris Shouts