Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

CS1061: does not contain a definition for and no extension method

Member lookup failed on both instance and extension methods. Type inference, missing using directives, target frameworks and packages explain most cases.

~4 min readC#
#.NET#C##Compiler Errors#Debugging
A .NET type crate missing a member slot, a cyan extension method shelf and amber using directive card

Introduction & Quick Summary

text
error CS1061: 'IEnumerable<string>' does not contain a definition for 'ToListAsync' and no accessible extension method 'ToListAsync' accepting a first argument of type 'IEnumerable<string>' could be found (are you missing a using directive or an assembly reference?)

The compiler resolved the receiver's type, searched instance members, then searched extension methods in scope, and found nothing. The message names both the receiver type and the missing member, so the diagnosis is a matter of asking why that type is what it is.

Five causes cover nearly everything:

  • The receiver is not what you expect. Where() returned IEnumerable<T> where you assumed IQueryable<T>, so the async extension does not apply.
  • A missing using. System.Linq, System.Text.Json, or your own namespace holding the extension method is not imported.
  • The package is not referenced. The type exists in a NuGet package that is installed for one project but not the one being compiled.
  • The target framework lacks the API. A method added in .NET 8 is not available when a library targets netstandard2.0.
  • A nullable or object receiver. object has almost no members, and a null-conditional chain can degrade an inferred type to object.
Receiver type in the errorWhat probably happened
IEnumerable<T>LINQ in-memory chain, not EF Core
objectdynamic, boxing, or an untyped deserialize
TaskMissing await before the call
stringMissing using System; inside a file with implicit usings off
IDisposableInterface typed variable, concrete type needed
Nullable<T>Dereference without .Value

Core Mechanics, Signatures & Reproducible Setup

Member lookup order is fixed: instance members on the type, then base types, then extension methods visible through using directives in the current file or namespace, then members brought in by using static. An extension method is only a candidate when the first parameter is assignable from the receiver type, and generic inference can fail for reasons the message does not show.

Reproduce a version of it with two files:

csharp
// Extensions.cs namespace App.Text; public static class StringExtensions { public static string Shout(this string value) => value.ToUpperInvariant() + "!"; }
csharp
// Program.cs var s = "hello".Shout(); // error CS1061: 'string' does not contain a definition for 'Shout'

Adding using App.Text; or enabling implicit global usings fixes it. A project-level fix is a global using:

csharp
// GlobalUsings.cs global using App.Text;

For the EF Core variant, the types must line up exactly:

csharp
using Microsoft.EntityFrameworkCore; IQueryable<Order> query = db.Orders.Where(o => o.Total > 0); var list = await query.ToListAsync(); // compiles IEnumerable<Order> materialized = query.AsEnumerable(); var bad = await materialized.ToListAsync(); // CS1061: 'IEnumerable<Order>' does not contain a definition for 'ToListAsync'

AsEnumerable() and ToList() drop to in-memory LINQ, which has no async operators. Use ToListAsync() before materializing, not after.

Key Comparison Table

SituationReceiver typeApplies toFix
System.Linq missingstringSelect, Where on arraysusing System.Linq;
EF async operatorsIEnumerable<T>ToListAsyncKeep IQueryable<T>
Custom extensionYour typeYour methodusing the namespace
Missing packageAnyType from NuGetdotnet add package
Older TFMstringContains(char, StringComparison)Multi-target or conditional compilation
Nullable receiverT?Any instance memberGuard or !
Fix approachScopeRiskWhen to prefer
Add usingSingle fileNoneFastest
Global usingWhole projectNamespace pollutionRepeatedly needed namespaces
Explicit interface castSingle callRuntime cast failureVariable typed too broadly
Multi-targetLibraryBuild time doublesDistributing a package
Package referenceProjectVersion conflictsGenuinely missing assembly

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

Case 1: Task used as Task<T>

csharp
var order = repository.GetOrderAsync(id); var id = order.OrderId; // CS1061: 'Task<Order>' has no definition for 'OrderId'

The fix is await, and the enclosing method must be async:

csharp
var order = await repository.GetOrderAsync(id); var id = order.OrderId;

Case 2: API differences across target frameworks

string.Contains(char) arrived in .NET Core 2.1, and Contains(string, StringComparison) only in .NET Core 2.1 as well. A library targeting netstandard2.0 cannot use them:

csharp
#if NETSTANDARD2_0 value.IndexOf(needle, StringComparison.OrdinalIgnoreCase) >= 0; #else value.Contains(needle, StringComparison.OrdinalIgnoreCase); #endif

Or use IndexOf unconditionally, which exists everywhere and avoids conditional compilation.

Case 3: Implicit usings made a project compile locally only

Projects created from .NET 6 templates enable ImplicitUsings and quietly import System, System.Linq, System.Collections.Generic and others. A file copied into an older project, or a project with <ImplicitUsings>disable</ImplicitUsings>, fails on methods that used to be free:

xml
<PropertyGroup> <ImplicitUsings>enable</ImplicitUsings> </PropertyGroup>

Prefer explicit usings in shared code so the dependency is visible.

Case 4: dynamic and COM interop

csharp
dynamic payload = JsonSerializer.Deserialize<object>(json)!; var name = payload.Name; // resolves at runtime, no CS1061

With dynamic the compiler stays silent and the call fails at runtime with RuntimeBinderException. If you see CS1061 instead, the type is statically known, so there is no ambiguity to chase.

Case 5: Interface versus concrete type

csharp
IList<string> items = GetItems(); var capacity = items.EnsureCapacity(10); // CS1061: IList has no EnsureCapacity

EnsureCapacity is on List<T>. Either change the variable's declared type or cast, accepting a possible InvalidCastException:

csharp
var list = items as List<string> ?? items.ToList(); var capacity = list.EnsureCapacity(10);

Case 6: Extension method shadowed by an instance method

An instance method with a compatible name always wins, even when its signature does not match your call. A type with Select(string) blocks an extension Select(Func<...>) from being chosen, and the error reports no overload rather than pointing at the extension. Check with typeof(MyType).GetMethods() before assuming the extension is out of scope.

Common Compilation/Runtime Mistakes & Version Gotchas

  • System.Linq is imported by implicit usings, but System.Linq.Async is a separate package. ToListAsync on IAsyncEnumerable<T> needs it, and the error text looks identical to the EF Core case.
  • EF Core 6 to 8 changed overloads. ExecuteDelete, ExecuteUpdate and bulk operations need a newer provider; using them against an older one gives CS1061 on DbSet<T>, not a version error.
  • Nullable reference types. string? x still exposes string members, but x! chains can hide the real null flow. Enable <Nullable>enable</Nullable> and let the compiler warn earlier.
  • Reference assemblies from a wrong SDK. Visual Studio can compile against a reference assembly pack that does not match the runtime; dotnet --info and the project's TargetFramework must agree.
  • Kotlin-style extension confusion. C# extension methods cannot override instance members and cannot add static members to a type; attempts always yield CS1061.
  • Source generators. A generated extension lives in a namespace defined by the generator; missing the package silently removes it while the call site still compiles against the old binary until a clean rebuild.

When a type mismatch drives the error, log GetType().FullName at runtime or inspect the intermediate type with the debugger, then compare the two candidate JSON payloads using the JSON formatter. If the difference came from a configuration switch such as a different serializer or API version, the diff tool over the two project files shows it in one pass. For reviewing the exact HTTP contract that produced an unexpected DTO, the status code reference settles whether the body is even valid for the verb.

Primary references: CS1061 in the C# compiler message reference explains the lookup rules, and extension methods documents scope and binding precedence.

Official references

primary documentation

The C# documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit C# work — they run entirely in this browser tab, so nothing you paste leaves your device.

All C# guides

More in C#

All C# guides

The guides filed next to this one in C#, in library order.