C# Error CS1940 – Multiple implementations of the query pattern were found for source type ‘{0}’. Ambiguous call to ‘{1}’.

C# Error

CS1940 – Multiple implementations of the query pattern were found for source type ‘{0}’. Ambiguous call to ‘{1}’.

Reason for the Error & Solution

Multiple implementations of the query pattern were found for source type ‘type’. Ambiguous call to ‘method’.

This error is generated when multiple implementations of a query method are defined and the compiler cannot disambiguate which one is best to use for the query. In the following example, both versions of Select have the same signature, because they both accept one int as an input parameter and have int as a return value.

To correct this error

  1. Provide only one implementation for each method.

Example

The following code generates CS1940:

// cs1940.cs  
using System; //must include explicitly for types defined in 3.5  
class Test  
{  
    public delegate int Dele(int x);  
    int num = 0;  
    public int Select(Func<int, int> d)  
    {  
        return d(this.num);  
    }  
    public int Select(Dele d) // CS1940  
    {  
        return d(this.num) + 1;  
    }  
    public static void Main()  
    {  
        var q = from x in new Test()  
        select x;  
    }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...