C# CS0117: 'X' does not contain a definition for 'Y'
CS0117 means the compiled assembly has no such member, usually from an older target framework or package. Check the API surface before editing code.

Introduction & Quick Summary
The build stops on a member that clearly exists in the documentation:
error CS0117: 'Math' does not contain a definition for 'Clamp'
error CS0117: 'HttpClient' does not contain a definition for 'GetFromJsonAsync'
error CS0117: 'File' does not contain a definition for 'ReadAllTextAsync'CS0117 means the compiler resolved the type but found no member with that name in the assembly it is compiling against. The usual cause is not a typo: it is an older assembly, because the project targets a framework version or a package version that predates the API.
Where it appears:
- A project targeting
netstandard2.0ornet6.0while the code uses APIs added in .NET 7 or later. - A NuGet package pinned to an old version, so an extension method the code calls does not exist yet.
- A
usingdirective missing for an extension method — although that case is usually CS1061, not CS0117. - Two assemblies with the same type name, where the compiler picked the wrong one.
- A source generator or analyzer that failed and left a partial type incomplete.
Quick answer: check the target framework and the package version before touching the code. If the API exists in the framework you claim to target, the referenced assembly is stale — restore, clean, and verify which assembly resolution actually won.
Core Mechanics, Signatures & Reproducible Setup
C# binds member access at compile time against the reference assemblies of the chosen target framework. Those assemblies are not the runtime DLLs on the machine; they come from the targeting pack in ~/.nuget/packages or the SDK's packs folder. A member that exists in the runtime but not in the targeting pack produces CS0117 even though the code would run.
Reproduce it with a one-project console app:
dotnet new console -n cs0117 -o cs0117
cd cs0117<!-- cs0117.csproj -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>// Program.cs
Console.WriteLine(Math.Clamp(11, 0, 10));
Console.WriteLine(await File.ReadAllTextAsync("data.txt"));With the .NET 6 targeting pack, Math.Clamp exists but File.ReadAllTextAsync also exists — both arrived in .NET Core 2.0/3.0, so this compiles. Change the target to netstandard2.0 and both fail:
error CS0117: 'Math' does not contain a definition for 'Clamp'
error CS0117: 'File' does not contain a definition for 'ReadAllTextAsync'netstandard2.0 is the API surface every modern .NET agrees on, and it predates both members. Raising TargetFramework to net8.0 fixes it without touching the code.
The member-lookup errors and what each one actually means:
| Error | Meaning | Typical fix |
|---|---|---|
| CS0117 | the type has no member with that name | wrong target framework or assembly version |
| CS1061 | no member and no accessible extension method | missing using for an extension, or wrong type |
| CS0103 | the name does not exist in the current context | missing using, typo, scope |
| CS0234 | the namespace does not exist in the namespace | missing package reference |
| CS0246 | the type or namespace could not be found | missing package or using |
| CS1501 | no overload takes that many arguments | signature changed between versions |
Key Comparison Table
The same source, compiled against different targets:
| API | netstandard2.0 | net6.0 | net8.0 | net10.0 |
|---|---|---|---|---|
Math.Clamp | absent | present | present | present |
File.ReadAllTextAsync | absent | present | present | present |
TimeProvider | absent | absent | present | present |
DistributedApplication | absent | absent | absent | present |
System.Text.Json source generator | package needed | built in | built in | built in |
Where the mismatch usually originates:
| Setting | File | Effect when wrong |
|---|---|---|
TargetFramework | .csproj | compiles against an older API surface |
PackageReference Version | .csproj | extension methods missing |
<Reference Include> with HintPath | .csproj | binds a stale DLL, often from bin/ |
global.json sdk.version | repository root | pins an older SDK than teammates use |
LangVersion | .csproj or Directory.Build.props | syntax errors, not CS0117 |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. Extension methods: CS1061 versus CS0117
HttpClient.GetFromJsonAsync lives in System.Net.Http.Json, not in System.Net.Http. Without the using directive the compiler reports a member that does not exist:
error CS1061: 'HttpClient' does not contain a definition for 'GetFromJsonAsync'
and no accessible extension method 'GetFromJsonAsync' accepting a first argument
of type 'HttpClient' could be foundAdding the using fixes it when the package is present:
using System.Net.Http.Json; // extension lives here
var client = new HttpClient { BaseAddress = new Uri("https://api.example.com/") };
var user = await client.GetFromJsonAsync<User>("/users/1");On netstandard2.0 the package reference is also required, because the namespace ships in a separate NuGet package:
<PackageReference Include="System.Net.Http.Json" Version="8.0.1" />The error text tells you which case you are in: CS1061 with the "extension method" sentence means a missing using or package, while CS0117 means the type genuinely has no such member in this assembly.
2. A stale reference from bin/
A legacy project referencing a DLL by path can bind an old copy that was built before the API existed:
<Reference Include="Acme.Core">
<HintPath>..\lib\Acme.Core.dll</HintPath>
</Reference>Check what the compiler actually loaded instead of trusting the path:
dotnet build -v:n | grep -i "Acme.Core" | head
strings lib/Acme.Core.dll | grep -c "GetFromJsonAsync"Prefer ProjectReference or PackageReference: both carry version metadata that the SDK validates, which turns a silent mismatch into a restore error.
3. Multi-targeting that compiles each target differently
A library that targets both netstandard2.0 and net8.0 can legitimately use an API only under one target, guarded by a preprocessor symbol:
#if NET8_0_OR_GREATER
var text = await File.ReadAllTextAsync(path);
#else
var text = File.ReadAllText(path);
#endifWithout the guard the netstandard2.0 leg fails with CS0117 while the net8.0 leg succeeds, and the error appears only in a full dotnet build — not in an IDE configured for one target. Use dotnet build -f netstandard2.0 to reproduce the failing leg in isolation.
4. Wrong type selected by the same name
Two namespaces with a JsonSerializer class produce member errors when the wrong one wins:
using System.Text.Json;
using Newtonsoft.Json; // both expose JsonSerializerThe compiler resolves the ambiguity with CS0104 before reaching CS0117, but alias-based resolution can hide the problem until a member call fails:
using Json = System.Text.Json.JsonSerializer;
var json = Json.Serialize(value, options); // Newtonsoft's options type is differentCheck the type's assembly in the IDE tooltip, or print it at run time with typeof(JsonSerializer).Assembly.FullName.
5. When the API exists but the SDK is old
global.json pins the SDK for a repository:
{ "sdk": { "version": "6.0.428", "rollForward": "latestFeature" } }With that file in place, dotnet --version reports 6.x even after installing .NET 8, and every project in the tree compiles against .NET 6 targeting packs. The symptom is a CS0117 for a .NET 8 API on a machine you believe has .NET 8 installed. dotnet --list-sdks shows all installed SDKs and resolves the confusion in one command.
Common Compilation/Runtime Mistakes & Version Gotchas
Adding <LangVersion>preview</LangVersion> to fix it. Language version controls syntax, not API availability. A preview language version cannot make a missing method exist, and it produces different errors instead of fixing this one.
Referencing the assembly from the GAC or a machine-wide folder. C:\Program Files\dotnet\shared\... contains runtime assemblies, not reference assemblies, and binding them directly bypasses the SDK's consistency checks. Use FrameworkReference or the targeting pack.
Upgrading the package but not the target framework. System.Text.Json 8.x supports netstandard2.0, so the package is not always the blocker; the API surface of the target framework decides. Look at the package's lib/ folders to see which target is being consumed.
Version differences worth knowing. .NET 8 removed several BinaryFormatter members that still compile on netstandard2.0 with a warning and become CS0117 on net8.0. .NET 9 turned some previously extension-only methods into instance methods, so code that relied on the using directive can fail after a target upgrade. ImplicitUsings (enabled by default in templates from .NET 6) hides which namespaces are imported, so a file that compiles in one project and fails in another often differs only in that property.
Comparing project files. When two projects disagree, diff the .csproj and Directory.Build.props with Diff, and inspect the generated project.assets.json (formatted with the JSON viewer) to see the exact assembly version that restore selected for each target.
Reference material: CS0117 compiler error and .NET target frameworks.
Official references
primary documentationThe C# documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit C# work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related C# guides
All C# guidesC# CS0246: The type or namespace name could not be found
CS0246 is a compile-time resolution failure: a missing using, package, target framework, or an unrestored project. Trace it backward from the symbol.
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.
C#: NullReferenceException: Object reference not set
The message never names the null. Read the stack trace, enable nullable reference types, and use null-conditional access instead of guessing.
.NET: The framework 'Microsoft.NETCore.App' was not found
A framework-dependent app asks for a runtime major that is absent. Install the matching runtime or publish self-contained, and match Docker tags.
More in C#
All C# guidesThe guides filed next to this one in C#, in library order.