不明确的参考

发布于 2024-10-22 23:48:04 字数 705 浏览 3 评论 0原文

我在解决方案中删除了一个项目,然后又重新添加了它。 自从阅读它以来......我现在收到了一个不明确的引用错误,我无法删除它。 查看该类的实现(出现错误),我看到它引用了两次:

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

命名空间仅查看一次,但此问题仅存在于 1 个部分视图中。

编辑:

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

MyViewModel 给出了不明确的错误,如果我查看所有可用的类,它会显示重复项,例如:

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

但是当我在同一个项目中打开另一个部分视图时,就很好了。这只是 1 部分似乎保留了重复的引用。

知道我该如何解决这个问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

旧时模样 2024-10-29 23:48:04

您是否尝试过右键单击解决方案并执行清理解决方案

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

蓝色星空 2024-10-29 23:48:04

听起来您的项目对同一程序集有两个不同的引用。

摆脱其中之一。

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

Get rid of one of them.

§普罗旺斯的薰衣草 2024-10-29 23:48:04

我删除了每个项目目录中的“bin”和“obj”子目录,错误消失了。

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

帥小哥 2024-10-29 23:48:04

我收到此错误消息,但我的项目仍然构建并运行良好几个月。这是因为有人将一个类放在一个名称空间中,该名称空间的大小写与该名称空间的所有其他实例不同,因此它们实际上是两个不同的名称空间。我们的代码在技术上是正确的,但 ASPX <%@ Register %> 指令抱怨它不明确,因为有两个不同的符号具有“相同”的名称; MyNamespaceMynamespace

检查你的大小写。

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.

巷子口的你 2024-10-29 23:48:04

您是否尝试过将其(Visual Studio)关闭然后再次打开?它对我有用......

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

醉城メ夜风 2024-10-29 23:48:04

可能您的项目具有指向解决方案中的程序集的链接,并且您的项目类具有指向引用程序集中的命名空间的 using 语句。

如果项目之间的程序集属于一个解决方案,请删除它们之间的链接。

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.

巷子口的你 2024-10-29 23:48:04

如果您引用了两个不同的版本,也可能会发生这种情况。如果您在问题项目中引用程序集,并且还引用具有相同引用但版本不同的另一个项目,则使用哪个引用是不明确的。

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.

寂寞清仓 2024-10-29 23:48:04

我的解决方案中也遇到了同样的问题,引用不明确。当我尝试引用两个引用之一时,我不可能 - 单击后它没有执行任何操作。
原因是通过项目引用和 Nuget 引用引用同一个类。

我刚刚转到 C:\Users{userName}.nuget\packages{projectName}\4.6.0\lib\net6.0{dllName} 并删除 dll 文件。现在它可以正常工作

在此处输入图像描述

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

旧城空念 2024-10-29 23:48:04

您收到此错误是因为您有两个具有相同名称和相同命名空间的类。您应该更改其中一个类的名称空间。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文