Ali Jockar
Ali Jockar

Reputation: 65

Error 130 - The call is ambiguous between the following methods or properties

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;
        }
    }
}

I use this function all over my project for validating an empty text Box. It works normally until I add one user control to one of my WinForms. In particular, when the data source of the Grid changes, an instance of that User control is added to my form, but I get this error.


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


I do not know what relationship there is between adding a user control and this error? If I delete the UserControl, my code does not work and I get an error. What do I do?

Upvotes: 2

Views: 2176

Answers (2)

Nelly
Nelly

Reputation: 522

I also had this error.

Always when I added a control in my project to one of my forms I couldn't compile any longer because of ambiguous call's to all of my extension methods.

In the end I saw that VS added a reference of my project to the same project, so the compiler got a problem with this. Then it does not help to delete your code, because the reference is still there.

I could solve the problem by removing this reference from my project. Maybe this helps anyone else.

Upvotes: 4

fhnaseer
fhnaseer

Reputation: 7277

This function is defined on two places. Check that. Compiler does not know which one to call. Find in your solution. There will be two functions of this name.

Upvotes: 0

Related Questions