-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
6.0 RC1: ImplicitUsings with .NET Framework 4.x - System.Net.Http is not available #59163
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsI have two NuGet packages I maintain with legacy .NET Framework support for 4.6.2 when I enabled ImplicitUsings on those projects they both failed to compile due to the inclusion of System.Net.Http which the legacy .NET Framework doesn't have available without adding a package dependency on System.Net.Http Error Message: error CS0234: The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) Failed workaround: <ItemGroup>
<Using Remove="System.Net.Http" />
</ItemGroup> Workaround: <ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup> Suggested fix: // <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
#if !NETFRAMEWORK
global using global::System.Net.Http;
#endif
global using global::System.Threading;
global using global::System.Threading.Tasks; Reproduced here for convenience just remove the package reference
|
.Net Framework 4.6.2 does include System.Net.Http, especially since it's in .Net Standard 2.0 which .NF 4.6.2 covers. The docs confirm it. |
@MichalPetryka that would be a no..... |
@buvinghausen I am not sure I fully understand. |
@karelz please see the OP the bottom has everything you need |
@buvinghausen I see your code link now. Also, I am not sure what this comment means:
Is there a chance to create HelloWorld-style CS file with project which would demonstrate the problem? That will help me identify where to route this. It does not seem to be problem of the NuGet package itself ... |
Here it is. Try to |
@karelz sorry I was on a conference call but it looks like @teo-tsirpanis got it covered. |
Normally System.Net.Http is not referenced by the .NET SDK by default I think on .NET Framework 4.6.2. I remember before I had to explicitly add But yes System.Net.Http exists by default with no need to download it separately, reference from a file external from what gets installed when you install the reference assemblies (or the ones provided by the .NET SDK that references a nuget package that acts as if you installed the targeting packs for the .NET Frameworks), etc. |
@AraHaan thank you for the input I was able to add the following lines to my Directory.Build.props files and now everything compiles and tests <ItemGroup Condition="'$(TargetFramework)'=='net462'">
<Reference Include="System.Net.Http" />
</ItemGroup> @karelz I don't know if this is something you still want to triage so I will leave it open for the time being but I don't need it kept open on my behalf as I should be able to publish to nuget without the added dependency. This was more an exploration of implicit usings than a must have deal in the end. |
If I target
I think this issue belongs |
@teo-tsirpanis Yeah I would imagine anything below net45 would be SOL. Task<T> came with .NET 4 and System.Linq came with .NET 3.5. |
FYI I bought this up a few weeks ago in the SDK issue for the global using feature and the response I got was that it was by-design as this feature is only supported for .NET 6 dotnet/sdk#19521 (comment) |
Duplicate of dotnet/sdk#19521 |
Thanks @martincostello for referencing that. It seems like dupe, so I marked it so. Not much we can do about it in System.Net.Http NuGet package ... |
I have two NuGet packages I maintain with legacy .NET Framework support for 4.6.2 when I enabled ImplicitUsings on those projects they both failed to compile due to the inclusion of System.Net.Http which the legacy .NET Framework doesn't have available without adding a package dependency on System.Net.Http
Error Message: error CS0234: The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
Failed workaround:
(Updated)
Workaround:
Suggested fix:
Reproduced here for convenience just remove the package reference
The text was updated successfully, but these errors were encountered: