question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CS0234 'Http' does not exist in the namespace 'System.Net' when targeting .NET Fx 4.x with implicit usings

See original GitHub issue

Describe the bug

C# 10 introduces global usings. The .NET 6 SDK ships with a default template for implicit usings. For the regular SDK (e.g., non-Web), this generated C# looks like:

// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

However, System.Net.Http is a namespace that does not exist in .NET Framework 4.x. Therefore, this namespace should not be imported implicitly.

To Reproduce

A csproj like this will suffice:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <Nullable>enable</Nullable>
    <LangVersion>10.0</LangVersion>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

</Project>

This will fail to build with:

Error | CS0234 | The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
aprillove2858commented, Jun 6, 2022

FUCK YOU STOP BY

On Mon, Jun 6, 2022, 3:34 PM Paul Williams @.***> wrote:

<Using Remove="System.Net.Http" /> does the trick.

— Reply to this email directly, view it on GitHub https://github.com/dotnet/sdk/issues/24146#issuecomment-1147896159, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXZ3LW2IOU7ANNX6EGH3RQ3VNZODXANCNFSM5PT6WVCQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

6reactions
pranavkmcommented, Mar 2, 2022

Therefore, this namespace should not be imported implicitly.

The default list of usings are primarily tailored for .NET 6 and newer apps, and aren’t enabled by default. You can use the Using itemgroup to specify a custom list of global usings to be used for your app, or use MSBuild to remove ones added by ImplicitUsings=Enable e.g. <Using Remove="System.Net.Http" />.

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.Net.Http: missing from namespace? (using .net 4.5)
See CS0234 'Http' does not exist in the namespace 'System.Net' when targeting .NET Fx 4.x with implicit usings. I fixed it by installing...
Read more >
Getting "The type or namespace name 'Http' does not exist ...
NET Framework Version 4.8.03761 When NCrunch is building my unit test ... or namespace name 'Http' does not exist in the namespace 'System....
Read more >
The Problem with C# 10 Implicit Usings
I tried using C# 10 implicit using statements and found that they had a ... compatibility and found that System.Net.Http could not be...
Read more >
Troubleshoot known issues - .NET MAUI
Can't locate the .NET MAUI workloads; Platform version isn't present; Type or namespace 'Default' doesn't exist; Xcode isn't currently ...
Read more >
Cannot use namespace System.Net.Http and others from . ...
I am using Unity 2017.3.0f3 and VS 2017 (ver. 15.5.2) with 4.6 .NET enabled. When I am trying to use some classes from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found