C# 编译器 : CS0121: The call is ambiguous between the following methods or properties

标签 c#

这是我见过的最疯狂的事情,因为 Fody 插件通过发出无效代码破坏了我的程序集,并且控制流在运行时随机变化......这次没有 Fody。

事实:

  • 整个故事都在一个项目中。
  • GetMessage 扩展方法已存在数周...
  • 问题从 2 小时开始出现,我无法弄清楚它是什么。
  • 只有一种 GetMessage 扩展方法。
  • 错误消息(见图片)列出了两个相同方法规范

    错误 CS0121 以下方法或属性之间的调用不明确:“ComiCalc.Data.ExceptionExtensions.GetMessage2(System.Exception)”和“ComiCalc.Data.ExceptionExtensions.GetMessage2(System.Exception)”ComiCalc。数据D:\2014Develop\.vsonline\ComiCalc\src\ComiCalc.Data\Services\UserService.cs 61

  • 如果我将调用和方法定义(仅在 2 个地方进行了 2 次编辑)更改为 GetMessage2,那么我会收到完全相同的错误消息,只是引用 GetMessage2。

  • 使用 VS 2015

有什么想法吗?

enter image description here

这是唯一的方法:

namespace ComiCalc.Data
{

    using System;
    using System.Data.Entity.Validation;
    using PluralTouch.DataAccess;
    // TODO: Move to PluralTouch
    public static class ExceptionExtensions
    {
        public static string GetMessage2(this Exception exception)
        {

            var message = exception.Message;
            if (exception is DbEntityValidationException)
            {
                message = ((DbEntityValidationException) exception).DbEntityValidationResultToString();
            }
            return message;
        }
    }
}

enter image description here

最佳答案

确保您没有在项目引用中引用输出二进制文件(即项目引用本身)。这在我过去使用 Resharper 时发生过(将输出二进制文件添加到项目引用中),因此扩展方法既在源代码中又在二进制引用中。

关于C# 编译器 : CS0121: The call is ambiguous between the following methods or properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31729186/

相关文章:

C#/WPF : Place Popup Control in Center of Screen?

c# - 是否可以有效使用更改音频 (mp3) 文件的哈希值

c# - 来自 OnEventActivityAsync 的数据在第一次之后不会更改 ConversationState

c# - 区分属性 protected 和 setter protected

c# - 如何在 C# 中使用正则表达式获取某个特定单词之前的数字?

c# - 使用 C# 代码隐藏将表动态添加到 ASP.NET Web 应用程序

c# - WPF TimeSpan 绑定(bind)到没有毫秒的标签

c# - 如何在现有的 AspNetUsers 表中添加一列

c# - 有条件地指定 nuget 包版本

c# - 序列化和反序列化域事件以在通用实现中持久化并从事件存储中检索