c# - 错误 130 - 以下方法或属性之间的调用不明确

标签 c# user-controls

public static class MyExtensions
{
    public static bool TextBoxIsEmpty(TextBox txtControl, ErrorProvider eP)
    {
        if (txtControl.Text == string.Empty)
        {
            eP.SetError(txtControl, "You must Enter something!");
            return true;
        }
        else
        {
            eP.Clear();
            return false;
        }
    }
}

我在整个项目中都使用此函数来验证空文本框。它正常工作,直到我将一个用户控件添加到我的 WinForm 之一。特别是,当网格的数据源更改时,该用户控件的实例将添加到我的表单中,但我收到此错误。


Error 129 The call is ambiguous between the following methods or properties: 'DominateVehicle.Class.MyExtensions.TextBoxIsEmpty(System.Windows.Forms.TextBox, System.Windows.Forms.ErrorProvider)' and 'DominateVehicle.Class.MyExtensions.TextBoxIsEmpty(System.Windows.Forms.TextBox, System.Windows.Forms.ErrorProvider)' D: \Vechel_Dominate\a\DominateVehicle\frmDefectClass.cs 30 41 DominateVehicle


不知道添加用户控件和这个错误有什么关系? 如果我删除 UserControl,我的代码将无法工作并且会收到错误消息。我该怎么办?

最佳答案

我也遇到了这个错误。

总是当我将项目中的控件添加到我的表单之一时,由于对所有扩展方法的调用不明确,我无法再编译。

最后我看到VS将我的项目的引用添加到同一个项目中,因此编译器遇到了问题。那么删除代码也无济于事,因为引用仍然存在。

我可以通过从我的项目中删除此引用来解决问题。也许这对其他人有帮助。

关于c# - 错误 130 - 以下方法或属性之间的调用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14579533/

相关文章:

c# - OpenGL 3.3+ - 着色器、属性、制服、输入/输出变量 - 如何、什么、何时、为什么?

c# - Visual Studio 2017 错误 : Cannot find project info for “” This can indicate a missing project reference - with Console App . NET Core 2.1

c# - 更改用C#编写的Active-X插件的用户类型名称

html - 前端 Rails 应用程序中的代码重用

c# - T 在此类签名中代表什么,我如何实例化此类?

c# - Solr - 为单个唯一 ID 存储多个 Word 文档

c# - 我如何在 XAML WPF 窗口中拥有动态元素

c# - 如何从用户控件中删除不必要的属性?

c# - 无法在设计 View 中使用用户控件打开 winform

c# - 如何检查字体是否支持特定样式