11

I have a server control as a class within my MySite assembly (i.e., my site's project not only contains aspx files but also contains server controls which those aspx files reference). I use the following code within an aspx file:

<%@ Register Assembly="MySite" Namespace="MySite.misc" TagPrefix="TAC" %>
...
<TAC:CustomACM ID="myID" runat="server" />

The class's code is as follows:

namespace MySite.misc
{
    public class CustomACM : AutoCompleteExtender, INamingContainer
    {
        //...
    }
}

The site works and compiles perfectly, but IntelliSense breaks within myID's children. Changing the namespace within both the class and the register directive to MySiteSC.misc fixes this, though using MySite.miscSC does not help. Neither MySiteSC nor miscSC is used elsewhere within my solution, and no other CustomACM class exists within any namespace.

ReSharper underlines "MySite" (i.e., part of the namespace within the register directive) in red with tooltip, "Register Directive is unused and can be safely removed \n Ambiguous Reference." Disabling ReSharper prevents this error from showing up, but does not fix the problem.

Is it possible for me to fix this problem without changing the namespace of the CustomACM control (and without moving the CustomACM control to a different assembly)?

Ryan Kohn
  • 11,921
  • 10
  • 50
  • 80
Brian
  • 24,434
  • 16
  • 74
  • 162

4 Answers4

5

Resharper is buggy here IMHO. The problem can be solved by clearing the caches of ReSharper (ReSharper > Options > General > Clear Caches), then restarting VS and build again. The message should disappear then. I know, that this isn't a solution really but it works.

Alexander Schmidt
  • 4,930
  • 4
  • 33
  • 71
  • Per my original post, disabling ReSharper entirely does not fix the problem. – Brian Jan 21 '14 at 14:08
  • @Brian What do you mean with "Per my original post"? I can't see any hint there that you disabled ReSharper. You said, that ReSharper underlines MySite. So it is still underlined when you disable ReSharper? Or am I getting something wrong? – Alexander Schmidt Jul 30 '14 at 07:42
  • 1
    From the original post: "Disabling ReSharper prevents this error from showing up, but does not fix the problem." The problem being, "The site works and compiles perfectly, but IntelliSense breaks within myID's children." – Brian Jul 30 '14 at 12:55
  • Believe it or not. I over-read it for minimum 10 times. Sorry! – Alexander Schmidt Jul 30 '14 at 15:48
1

To enable your control to be used declaratively in a page, you must map a tag prefix to your control's namespace.

In your custom server control project, have you added the TagPrefixAttribute attribute in your file AssemblyInfo.cs?

You have to add this line at the end of the file to create a mapping between the namespace and the prefix.

[assembly: TagPrefix("MySite.misc", "TAC")]

Add this line at the beginning of the file:

Using System.Web.UI;

After you do that, whenever you drag a custom server control from the toolbox to the .aspx page, VS should automatically add the Register directive.

Alternatively, instead of using register directive you could specify the tag prefix/namespace mapping in the web.config file if your custom control will be used in multiple pages in a web application.

<?xml version="1.0"?>
<configuration>
  <system.web>    
   <pages>
     <controls>
       <add tagPrefix="TAC" Assembly="MySite" 
         namespace="MySite.misc">
       </add>
     </controls>
   </pages>
  </system.web>
</configuration>
Only You
  • 2,001
  • 1
  • 20
  • 33
  • After doing this, I was able to use the toolbox to drag a CustomACM control to a page. Doing so automatically added a register directive to the top of the page, but the newly added register directive still suffered from the ambiguous reference problem. – Brian Jul 20 '12 at 13:42
  • @ydd1987: No, I'm still using the workaround I mention in the original question (i.e., using a different namespace for the affected control). – Brian Sep 18 '13 at 12:54
0

Check your web.config file

<assemblies>
...
</assemblies> 

section to see if maybe you have duplicate references to MySite.misc

TheMoot
  • 2,593
  • 4
  • 22
  • 26
0

I've solved a similar problem by deleting the .suo-file (Solution User Options (.Suo) File)

Pavlo Neiman
  • 7,068
  • 3
  • 25
  • 26