Ambiguous Reference in namespace
Asked Answered
F

4

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)?

Flagon answered 26/4, 2012 at 22:6 Comment(2)
This is Web Application and not a Web Site correct? (you aren't storing your cs files in App_Code)Eke
It is a Web Application and I am not using App_Code.Flagon
B
6

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.

Bitchy answered 21/1, 2014 at 11:15 Comment(4)
Per my original post, disabling ReSharper entirely does not fix the problem.Flagon
@Flagon 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?Bitchy
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."Flagon
Believe it or not. I over-read it for minimum 10 times. Sorry!Bitchy
H
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>
Hardbitten answered 20/7, 2012 at 2:33 Comment(2)
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.Flagon
@ydd1987: No, I'm still using the workaround I mention in the original question (i.e., using a different namespace for the affected control).Flagon
C
0

Check your web.config file

<assemblies>
...
</assemblies> 

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

Clupeoid answered 18/7, 2012 at 19:44 Comment(3)
No, there are 0 references to MySite in my web.config assemblies. When I add one, it does resolve properly, but does not prevent the error.Flagon
Did you check references under property explorer for a duplicate listing?Clupeoid
There are no duplicate listings.Flagon
S
0

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

Scoggins answered 31/12, 2014 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.