Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous Reference in namespace

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

like image 768
Brian Avatar asked Apr 26 '12 22:04

Brian


People also ask

What is ambiguous reference?

An ambiguous reference is the situation in which a sentence contains a pronoun that could refer to either of two nouns in the same sentence or (using our new vocabulary word) where we have a pronoun but we aren't sure what its antecedent is.

How to resolve ambiguous reference c#?

I had similar problem that the class had ambiguous reference for the SAME namespace, so I deleted a specific Project (under Dependencies/{my.prj.name}. API) which had duplicated reference. After that I referenced Project back with using of CTRL+. Hope it'll work for you.

What is ambiguous error in C#?

ambiguity error is that you named field and property tha same name "colour". change the property definition f.e. public string Colour { get { return colour;} set { colour = value;} } Copy link CC BY-SA 2.5. Follow this answer to receive notifications.


2 Answers

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.

like image 140
Alexander Schmidt Avatar answered Nov 06 '22 12:11

Alexander Schmidt


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>
like image 42
Only You Avatar answered Nov 06 '22 13:11

Only You