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

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...