C#
using declarations
version compatibility
compiler error
language features

Feature 'using declarations' is not available in C 7.3. Please use language version 8.0 or greater - Error on one machine but works on another

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

This compiler error appears when one environment builds the project with C# 7.3 while another environment uses a compiler that supports C# 8.0 or later. The code itself is not randomly failing. The machines are simply resolving different language versions, and the fix is to make that toolchain choice explicit.

Why the Code Works on One Machine but Not Another

using declarations were introduced in C# 8.0. The syntax looks like this:

csharp
using var client = new HttpClient();

If one machine is building with a newer SDK or compiler, that line compiles. If another machine is pinned to an older SDK or project configuration that resolves C# 7.3, it fails with the language-version error.

The difference usually comes from one of these:

  1. different installed .NET SDK versions
  2. a missing or ignored global.json
  3. LangVersion set differently in a project or imported props file
  4. IDE-specific build tooling that does not match the CLI

Inspect the Active SDK and Compiler Context

Before editing project files, check what each machine is actually using.

bash
dotnet --info
dotnet --list-sdks

These commands quickly reveal whether the machines are resolving different SDK families. If they are, that already explains why the same repository behaves differently.

It is also worth checking the project file for an explicit language version:

xml
1<PropertyGroup>
2  <TargetFramework>net8.0</TargetFramework>
3  <LangVersion>8.0</LangVersion>
4</PropertyGroup>

Remember that target framework and language version are related but not identical. A project can target a modern runtime while still using an older language version if the configuration says so.

Set LangVersion Explicitly

If your codebase uses C# 8.0 features, say so in the project file instead of depending on machine defaults.

xml
1<Project Sdk="Microsoft.NET.Sdk">
2  <PropertyGroup>
3    <TargetFramework>net8.0</TargetFramework>
4    <LangVersion>8.0</LangVersion>
5  </PropertyGroup>
6</Project>

This makes the compiler expectation part of source control rather than part of a developer workstation accident. If you manage several projects, consider centralizing the setting in a shared props file.

Pin the SDK With global.json

An explicit language version helps, but SDK drift can still cause surprises. A repository-level global.json keeps local and CI builds aligned on the same SDK band.

json
1{
2  "sdk": {
3    "version": "8.0.204",
4    "rollForward": "latestFeature"
5  }
6}

Once committed, this file tells dotnet which SDK to prefer from the repository root. That reduces the chances that one developer silently compiles with a newer default than everyone else.

Use a Fallback Syntax if You Cannot Upgrade Yet

If a project must stay on C# 7.3, rewrite the code to the older using statement form instead of the C# 8.0 declaration.

csharp
1using (var client = new HttpClient())
2{
3    var text = await client.GetStringAsync("https://example.com");
4    Console.WriteLine(text.Length);
5}

This produces the same disposal behavior while staying compatible with the older compiler. It is a good short-term fix when the language upgrade has to wait for broader tooling or policy reasons.

Verify the Fix in Both Local and CI Builds

After updating the configuration, rebuild in a clean environment.

bash
dotnet clean
dotnet restore
dotnet build -c Release

Do this on the machine that was failing and in CI. If the problem remains, inspect whether one subproject overrides LangVersion or whether an IDE is using a different build pipeline than the dotnet CLI.

Common Pitfalls

The most common mistake is assuming the target framework automatically determines language features. Another is fixing the issue only on one developer machine by installing a newer SDK, while leaving the repository configuration ambiguous. Teams also forget that multi-project solutions can hide one older project that still pins LangVersion lower than the rest of the solution.

Summary

  • This error is a language-version mismatch, not a random compiler failure.
  • 'using declarations require C# 8.0 or later.'
  • Check dotnet --info, installed SDKs, and any explicit LangVersion settings.
  • Pin the expected SDK with global.json and set LangVersion in source control.
  • If upgrade is blocked, use the older using (...) statement syntax instead.

Course illustration
Course illustration

All Rights Reserved.