CS0234 'Http' does not exist in the namespace 'System.Net' when targeting .NET Fx 4.x with implicit usings
See original GitHub issueDescribe 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:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FUCK YOU STOP BY
On Mon, Jun 6, 2022, 3:34 PM Paul Williams @.***> wrote:
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 byImplicitUsings=Enable
e.g.<Using Remove="System.Net.Http" />
.