Could not find an implementation of the query pattern for source type

Problem

Any time you try to use a Linq extension method (such as Select() to transform list elements) and you haven’t added ‘using System.Linq’, you’ll get a compiler error like this:

Could not find an implementation of the query pattern for source type ‘Your Type’.  ‘Select’ not found.

In newer versions, the error looks like this:

CS1061 ‘IEnumerable’ does not contain a definition for ‘Select’ and no accessible extension method

Solution

The error message is a bit odd, but the solution is simple: add ‘using System.Linq’ to the top of the source file, like this:

using System.Linq;

var list = GetList();

foreach(var name in list.Select(t => t.ToLower()))
{
    Console.WriteLine(name);
}
Code language: C# (cs)

Now the compiler error will go away because the compiler can see that Select() is an extension method in System.Linq.

In new versions, ‘System.Linq’ is added by default when you add a C# source file. Furthermore, in the latest versions, ‘System.Linq’ is automatically included as part of the implicit global usings. You will run into this error if you disable implicit global usings (ImplicitUsings in .csproj) and have existing code that is using Linq extensions.

3 thoughts on “Could not find an implementation of the query pattern for source type”

Leave a Comment