ambiguous reference

2019-04-03 15:12发布

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?

7条回答
你好瞎i
2楼-- · 2019-04-03 15:24

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

查看更多
We Are One
3楼-- · 2019-04-03 15:33

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

查看更多
小情绪 Triste *
4楼-- · 2019-04-03 15:35

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

Get rid of one of them.

查看更多
放我归山
5楼-- · 2019-04-03 15:35

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.

查看更多
趁早两清
6楼-- · 2019-04-03 15:36

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.

查看更多
来,给爷笑一个
7楼-- · 2019-04-03 15:42

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.

查看更多
登录 后发表回答