Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

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.

~5 min readC#
#csharp#dotnet#cs0117#target-framework
Bold white headline reading MEMBER MISSING with a .NET crate exposing an empty amber API slot on the right.

Introduction & Quick Summary

The build stops on a member that clearly exists in the documentation:

code
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.0 or net6.0 while 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 using directive 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:

bash
dotnet new console -n cs0117 -o cs0117 cd cs0117
xml
<!-- cs0117.csproj --> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net6.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> </Project>
csharp
// 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:

code
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:

ErrorMeaningTypical fix
CS0117the type has no member with that namewrong target framework or assembly version
CS1061no member and no accessible extension methodmissing using for an extension, or wrong type
CS0103the name does not exist in the current contextmissing using, typo, scope
CS0234the namespace does not exist in the namespacemissing package reference
CS0246the type or namespace could not be foundmissing package or using
CS1501no overload takes that many argumentssignature changed between versions

Key Comparison Table

The same source, compiled against different targets:

APInetstandard2.0net6.0net8.0net10.0
Math.Clampabsentpresentpresentpresent
File.ReadAllTextAsyncabsentpresentpresentpresent
TimeProviderabsentabsentpresentpresent
DistributedApplicationabsentabsentabsentpresent
System.Text.Json source generatorpackage neededbuilt inbuilt inbuilt in

Where the mismatch usually originates:

SettingFileEffect when wrong
TargetFramework.csprojcompiles against an older API surface
PackageReference Version.csprojextension methods missing
<Reference Include> with HintPath.csprojbinds a stale DLL, often from bin/
global.json sdk.versionrepository rootpins an older SDK than teammates use
LangVersion.csproj or Directory.Build.propssyntax 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:

code
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 found

Adding the using fixes it when the package is present:

csharp
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:

xml
<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:

xml
<Reference Include="Acme.Core"> <HintPath>..\lib\Acme.Core.dll</HintPath> </Reference>

Check what the compiler actually loaded instead of trusting the path:

bash
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:

csharp
#if NET8_0_OR_GREATER var text = await File.ReadAllTextAsync(path); #else var text = File.ReadAllText(path); #endif

Without 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:

csharp
using System.Text.Json; using Newtonsoft.Json; // both expose JsonSerializer

The compiler resolves the ambiguity with CS0104 before reaching CS0117, but alias-based resolution can hide the problem until a member call fails:

csharp
using Json = System.Text.Json.JsonSerializer; var json = Json.Serialize(value, options); // Newtonsoft's options type is different

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