Stephen Lacy
Stephen Lacy

Reputation:

Unrecognized Tag Prefix or Device Filter in Visual Studio 2008

I have a set of web controls that are in an assembly referenced by a website. I can build and run everything without a problem, however when I look at an aspx page where the controls are being used I get a green underline beneath the Tag Prefix.

<%@ Register Assembly="MyProject.UI.ControlLibrary" Namespace="MyProject.UI.ControlLibrary.Web" TagPrefix="ControlLibrary" %>
<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" Runat="Server">
    <ControlLibrary:ListView ID="List" runat="server"/>
</asp:Content>

So in this example I'd get a green underline under ControlLibrary and when I hover over it it says Unrecognized Tag Prefix or Device Filter 'ControlLibrary'

The code was written in a previous version of Visual Studio, I have another assembly also containing Web controls and that seems to work fine.

Any ideas as to what could be causing the problem?

Upvotes: 6

Views: 10245

Answers (5)

Anthony Graglia
Anthony Graglia

Reputation: 5435

Place the <%@ Import %> directive above the <%@ Register %> directive:

<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>

<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Upvotes: 3

Richard Collette
Richard Collette

Reputation: 5703

In my case, I have found that if the control assembly is already registered to a prefix in the web.config and then you try to register it to a different prefix using @register, then you will get this error message.

Upvotes: 1

Stephen Lacy
Stephen Lacy

Reputation:

No idea why this works but it does. When I change namespace of one of the listview control to MyProject.UI.ControlLibrary from MyProject.UI.ControlLibrary.Web and repoint the <% register then it works fine.

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630559

Try changing the reference to be in the web.config and see what error if any results? Here's an example of the root <asp: tag additions for a location reference. I like this approach because it keeps the pages cleaner as well if you're using the library much at all. See if get the same result after moving the library reference.

<system.web>
  <pages>
    <controls>
      <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Update - Based on your comment, try deleting everything in

Drive:\Documents and Settings\[User]\ApplicationData\Microsoft\VisualStudio\9.0\ReflectedSchemas

or short version:

%APPDATA%\Microsoft\VisualStudio\9.0\ReflectedSchemas\

Upvotes: 3

Vilx-
Vilx-

Reputation: 106970

It's hard to say what the cause is, but the ASP.NET XML parser in Visual Studio often has problems like these. Here are a few possible workarounds I have found, perhaps some of them will work for you as well:

  • After opening the .aspx file, wait a little bit. It takes a moment for VS to parse the file and set up its IntelliSense;
  • Try compiling the project while the .aspx file is open and on screen. A successful build often clears these issues up. If that doesn't work, try rebuilding the project or even the whole solution. And again - wait a little bit.
  • If all else fails, put the tag prefix definition in the web.config file:

    <configuration><system.web><pages><controls>
        <add tagPrefix="ControlLibrary" namespace="MyProject.UI.ControlLibrary.Web" assembly="MyProject.UI.ControlLibrary"/>
    </controls></pages></system.web></configuration>
    

    Of course, try rebuilding, etc.

Upvotes: 1

Related Questions