ambiguous reference
Asked Answered
A

9

20

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?

Alethaalethea answered 16/3, 2011 at 13:16 Comment(0)
C
47

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

Customs answered 16/3, 2011 at 13:19 Comment(3)
i did clean several times..but it took a manual clean to sort it. thanks allAlethaalethea
Yer I had to do a manual as well to solve the issue but thanks for that.Rustproof
Great manual clean instructions from this answer: https://mcmap.net/q/476820/-how-to-resolve-incorrect-quot-ambiguous-reference-quot-from-resharper-on-class-inheritance.Eucalyptol
L
4

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

Get rid of one of them.

Lyns answered 16/3, 2011 at 13:19 Comment(0)
J
2

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

Joy answered 3/11, 2019 at 14:44 Comment(0)
L
1

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.

Lazes answered 6/12, 2012 at 15:0 Comment(0)
M
1

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

Melonie answered 14/11, 2013 at 14:59 Comment(0)
W
0

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.

Workbook answered 17/7, 2014 at 3:10 Comment(0)
C
0

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.

Cuisse answered 1/5, 2017 at 14:49 Comment(2)
is there anything that you can do to resolve this? i.e. you want the 2 different versions present.Bemire
How to get around this error? Got exactly same problem as SylviaConvivial
H
0

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

Hartley answered 3/10, 2023 at 7:42 Comment(0)
L
-2

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.

Lundell answered 16/3, 2011 at 13:18 Comment(2)
try to remove the reference and make sure you are referencing by project.Lundell
done. its only the 1 partialview which is retaining the weird reference. rebooted my machine/cleaned solution/ cleared out temp asp.net folderAlethaalethea

© 2022 - 2024 — McMap. All rights reserved.