nologo
nologo

Reputation: 6288

ambiguous reference

I removed a project in my solution and then later re-added it. Since reading it.. I'm getting an ambiguous reference error now which I can't remove. viewing the implementation of the class (which is getting the error) I see it references it twice:

> ClassName (myclass.Class)    myclass.Class
> ClassName (myclass.Class)    myclass.Class, Version=1.0.0.0

the namespace is only viewed once, but this problem only exists in 1 partial view.

EDIT:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyClass.Class.MyViewModel>" %>

MyViewModel is giving the ambiguous error, if i view all the available classes it shows duplicates like:

MyClass.Class.MyViewModel
MyClass.Class.MyViewModel
MyClass.Class.MyOtherViewModel
MyClass.Class.MyOtherViewModel

but when I open another partial view in the same project, it's fine. It's just the 1 partial that seems to be retaining the duplicate reference.

Any idea how I can resolve this?

Upvotes: 20

Views: 37226

Answers (9)

Lukman
Lukman

Reputation: 79

I had a same issue with ambiguous reference in my solution. When I tried to reference one of two references I was not possible - it did no action after clicking. The reason was referencing same class via project reference and Nuget reference.

I just went to C:\Users{userName}.nuget\packages{projectName}\4.6.0\lib\net6.0{dllName} and delete dll file. Now it works properly

enter image description here

Upvotes: 0

Ryan Penfold
Ryan Penfold

Reputation: 803

I deleted the "bin" and "obj" sub-directories in each project's directory and the error disappeared.

Upvotes: 2

Chad Hedgcock
Chad Hedgcock

Reputation: 11775

This can also happen if you have references two different versions. If you're referencing an assembly in your problem project and also referencing another project that has the same reference but a different version, it's ambiguous which reference to use.

Upvotes: 0

Fragment
Fragment

Reputation: 1585

Probably your project had a link to an assembly in your solution and also your project class has a using statement to the namespace in referenced assembly.

Remove link to an assembly between projects if they belong to one solution.

Upvotes: 0

Sam Jones
Sam Jones

Reputation: 4618

Have you tried turning it (Visual Studio) off and on again? It worked for me...

Upvotes: 1

mo.
mo.

Reputation: 4245

I was getting this as an erroneous error message, and my project still built and ran fine for months. It was because someone had put a class in a namespace with different capitalisation to all the other instances of that namespace, so they were effectively two different namespaces. Our code was technically correctl, but the ASPX <%@ Register %> directive complained that it was ambiguous because there were two different symbols with the "same" name; MyNamespace and Mynamespace.

Check your capitalisation.

Upvotes: 1

SLaks
SLaks

Reputation: 887453

It sounds like your project has two different references to the same assembly.

Get rid of one of them.

Upvotes: 4

Sergi Papaseit
Sergi Papaseit

Reputation: 16174

Have you tried right-clicking the solution and doing Clean Solution?

Upvotes: 47

Ghyath Serhal
Ghyath Serhal

Reputation: 7632

You are getting this error because you have two class with the same name and the same namespace. You should change the namespace of one of the classes.

Upvotes: -2

Related Questions