HomeCSharpC# Error CS1943 – An expression of type ‘{0}’ is not allowed in a subsequent from clause in a query expression with source type ‘{1}’. Type inference failed in the call to ‘{2}’.

C# Error CS1943 – An expression of type ‘{0}’ is not allowed in a subsequent from clause in a query expression with source type ‘{1}’. Type inference failed in the call to ‘{2}’.

C# Error

CS1943 – An expression of type ‘{0}’ is not allowed in a subsequent from clause in a query expression with source type ‘{1}’. Type inference failed in the call to ‘{2}’.

Reason for the Error & Solution

An expression of type ‘type’ is not allowed in a subsequent from clause in a query expression with source type ‘type’. Type inference failed in the call to ‘method’.

All range variables must represent queryable types.

To correct this error

  1. Make sure that the type is a queryable type that implements IEnumerable, IEnumerable<T> or a derived interface, or any other type which has a query pattern defined for it.

  2. If the type is a non-generic IEnumerable, provide an explicit type on the range variable.

Example

The following code generates CS1943:

// cs1943.cs  
using System.Linq;  
class Test  
{  
    class TestClass  
    { }  
    static void Main()  
    {  
        int[] nums = { 0, 1, 2, 3, 4, 5 };  
        TestClass tc = new TestClass();  
  
        var x = from n in nums  
                from s in tc // CS1943  
                select n + s;  
    }  
}  

Leave a Reply

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...