ambiguous reference

人走茶凉 提交于 2019-12-05 10:06:26

问题


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?


回答1:


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




回答2:


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

Get rid of one of them.




回答3:


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.




回答4:


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




回答5:


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.




回答6:


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.




回答7:


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




回答8:


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.



来源:https://stackoverflow.com/questions/5325841/ambiguous-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!