Skip to content

HttpClient 4.3.2 broken on Mono #21777

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

Closed
mattjohnsonpint opened this issue May 18, 2017 · 53 comments
Closed

HttpClient 4.3.2 broken on Mono #21777

mattjohnsonpint opened this issue May 18, 2017 · 53 comments

Comments

@mattjohnsonpint
Copy link
Contributor

Hopefully this is the right place to report this. If not, please move and/or let me know where to report.

HttpClient appears to be broken when running on Mono with the latest release. Consider the following:

Install-Package System.Net.Http -Version 4.3.1
using System;
using System.Net.Http;

namespace HttpClientTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new HttpClient();
            var response = client.GetAsync("https://www.microsoft.com/net").Result;
            Console.WriteLine(response.StatusCode);
        }
    }
}

Compile with VS 2017, targeting .NET Framework 4.6.1. Run from the Windows command line:

HttpClientTest.exe

Works, no problem. Run under Mono, and also works.

mono HttpClientTest.exe

Now upgrade to 4.3.2

Update-Package System.Net.Http -Version 4.3.2

Run again. Works on .NET Framework, but under Mono, I get a MissingMethodException.

Unhandled Exception:
System.MissingMethodException: Method 'System.Net.Logging.get_On' not found.
  at System.Net.Http.HttpMessageInvoker.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x0003d] in <09d4a140061c48849b6322067e841931>:0 
  at System.Net.Http.HttpClient.SendAsync (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) [0x00049] in <09d4a140061c48849b6322067e841931>:0
  at System.Net.Http.HttpClient.GetAsync (System.Uri requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) [0x0000c] in <09d4a140061c48849b6322067e841931>:0
  at System.Net.Http.HttpClient.GetAsync (System.Uri requestUri, System.Net.Http.HttpCompletionOption completionOption) [0x00008] in <09d4a140061c48849b6322067e841931>:0
  at System.Net.Http.HttpClient.GetAsync (System.Uri requestUri) [0x00000] in <09d4a140061c48849b6322067e841931>:0
  at System.Net.Http.HttpClient.GetAsync (System.String requestUri) [0x00008] in <09d4a140061c48849b6322067e841931>:0
  at HttpClientTest.Program.Main (System.String[] args) [0x00007] in <8019b64f4f864b30ba0f2936c90cfab0>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Method 'System.Net.Logging.get_On' not found.
  at System.Net.Http.HttpMessageInvoker.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x0003d] in <09d4a140061c48849b6322067e841931>:0 
  at System.Net.Http.HttpClient.SendAsync (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) [0x00049] in <09d4a140061c48849b6322067e841931>:0
  at System.Net.Http.HttpClient.GetAsync (System.Uri requestUri, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) [0x0000c] in <09d4a140061c48849b6322067e841931>:0
  at System.Net.Http.HttpClient.GetAsync (System.Uri requestUri, System.Net.Http.HttpCompletionOption completionOption) [0x00008] in <09d4a140061c48849b6322067e841931>:0
  at System.Net.Http.HttpClient.GetAsync (System.Uri requestUri) [0x00000] in <09d4a140061c48849b6322067e841931>:0
  at System.Net.Http.HttpClient.GetAsync (System.String requestUri) [0x00008] in <09d4a140061c48849b6322067e841931>:0
  at HttpClientTest.Program.Main (System.String[] args) [0x00007] in <8019b64f4f864b30ba0f2936c90cfab0>:0

In another app (which I can't post here), I get others as well:

System.MissingFieldException: Field 'System.Net.ExceptionHelper.WebPermissionUnrestricted' not found.
System.MissingMethodException: Method 'System.Net.ServicePointManager.CloseConnectionGroups' not found.

Same results on Mono 4.8.0 or 5.0.0.

@mattjohnsonpint
Copy link
Contributor Author

@blowdart - Could this be a side effect of #21591?

@karelz
Copy link
Member

karelz commented May 18, 2017

@marek-safar @ericstj any insight here?

@blowdart
Copy link
Contributor

Shouldn't have affected it

@marek-safar
Copy link
Contributor

All versions of System.Net.Http are broken on Mono because they use private API available in .NET assemblies only (bad InternalsVisibleTo). To workaround that Mono has a hack to disable loading such assemblies and use always Mono's ones. You can simply fix it by deleting System.Net.Http.dll from your bin folder or wait for Mono 5.2 with updated table of broken assemblies.

@ericstj this is again issue we reported months ago as https://github.com/dotnet/corefx/issues/15112 which you marked as fixed but the assembly does not have your fix. Could you please re-address the issue.

@ericstj
Copy link
Member

ericstj commented May 18, 2017

@marek-safar the fix for https://github.com/dotnet/corefx/issues/15112 has not yet been released. That is part of the .NET Core 2.0 release. Package 4.3.2 is a servicing release for .NET Core 1.1.

@karelz
Copy link
Member

karelz commented May 18, 2017

Do we need to backport it? Or should we just wait for 2.0 to ship?

@mj1856 can you please validate it on .NET Core 2.0 Preview 1 bits? We want to confirm the problem is gone ...

@marek-safar
Copy link
Contributor

I see. I had no idea .NET framework specific issue is part of .NET Core 2.0 release.

@ericstj
Copy link
Member

ericstj commented May 18, 2017

It's a package related issue and the packages ship with .NET Core. I do think there is an interesting pivot here. Many of the packages which you care about do not ship in 2.0, instead we are shipping the NETStandard.Library.NETFramework package and deprecating the standalone packages.

@mattjohnsonpint
Copy link
Contributor Author

@karelz - I tried the latest 4.4.0.preview1-25218-03 from the myget feed, and it has the same issue.

@ericstj
Copy link
Member

ericstj commented May 18, 2017

@mj1856 we no longer produce this package as I mentioned above. You can use the NETStandard.Library.NETFramework package in its place.

@mattjohnsonpint
Copy link
Contributor Author

@marek-safar - just to confirm, I deleted System.Net.Http.dll from the bin dir and indeed it runs fine. I assume because the dll is not found in the local directory it binds to a copy Mono provides?

@mattjohnsonpint
Copy link
Contributor Author

It still gives the error when using the NETStandard.Library.NETFramework package instead of just System.Net.Http. I tried both 2.0.0-preview1-25305-02 from Nuget, and 2.0.0-preview2-25317-01 from the MyGet feed.

@marek-safar's explaination makes sense to me. Our plan is to just stay on 4.3.1 when running on Mono until Mono 5.2 ships with the updated table. Just not sure if this approach will work for others.

I have to say - I'm concerned about the "deprecating the standalone packages" bit. Pulling in NETStandard.Library.NETFramework blew up the number of .dll's in the output, including things I don't need here, like System.Drawing, etc. I liked the individual packages approach. I hope they stay. Is this being discussed on another issue somewhere?

@karelz
Copy link
Member

karelz commented May 18, 2017

@mj1856 there are downsides of many packages - e.g. VS showing you 30 of them that you depend on. So it has pros and cons.

Can someone confirm that there is reasonable path forward and decent user experience as well? I hope users don't have to delete packages, etc. when upgrading their projects. That would be pretty unfortunate.

@marek-safar
Copy link
Contributor

@ericstj is there any doc how NETStandard.Library.NETFramework package is suppose to be used or migrated to? It now has PreferInbox flag but as nobody told us about new APIs there, it'll crash at runtime on Mono due to API mismatch.

@ericstj
Copy link
Member

ericstj commented May 19, 2017

I believe all the APIs in there are all part of netstandard 2.0. /cc @weshaggard @davidsh

The plumbing for NETStandard.Library.NETFramework is still being worked on, coordinated by @terrajobst. The short of it is that it will be auto-referenced by NuGet when any ns2.0 package is installed to a packages.config-based project, and injected automatically by targets in any PackageReference-based target (similar to how netcoreapp and netstandard work today).

@sfmoloney
Copy link

sfmoloney commented Jul 14, 2017

@marek-safar @ericstj Hi guys I was wondering if you know if we have a resolution to the issue raised here? ... e.g. the missing method.

@ericstj
Copy link
Member

ericstj commented Jul 24, 2017

I think two things need to happen for this to work:

  1. mono adds all APIs that are part of netstandard2.0 (I believe this is in progress and I suspect the latest mono build will have them).
  2. mono prefers its own copy of System.Net.Http.dll rather than the one we build and include for windows desktop apps.

@marek-safar can you comment on these? Should we open an issue in the mono repo?

@marek-safar
Copy link
Contributor

The resolution is described above link, manually delete the file or upgrade to recent Mono version (e.g. 5.2) which has updated hacks for broken NETStandard assemblies.

@mattjohnsonpint
Copy link
Contributor Author

@marek-safar I think Mono 5.2 hasn't released yet?

@marek-safar
Copy link
Contributor

It's available http://www.mono-project.com/download/alpha/ but still in preview

@seanamos
Copy link

Running into this on 5.2.0 Stable (5.2.0.215) windows. Trying to confirm something works correctly with mono.

System.MissingMethodException: Method 'System.Net.Logging.get_On' not found.
  at System.Net.Http.HttpMessageInvoker.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00027] in <2b584c66184d490c9a91f80f1c75dcc0>:0
  at System.Net.Http.HttpClient.SendAsync (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) [0x0007a] in <2b584c66184d490c9a91f80f1c75dcc0>:0
  at System.Net.Http.HttpClient.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00000] in <2b584c66184d490c9a91f80f1c75dcc0>:0

Removing System.Net.Http.dll does not allow me to work around the problem either:

Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. assembly:System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:<unknown type>

@mickbyrne
Copy link

Is there any kind of fix for this yet? I've got a console app on .NET Framework 4.7, using the latest version of Visual Studio for Mac which comes with Mono 5.2.0.224. I get this error even after deleting the System.Net.Http.dll from my bin directory.

@sushihangover
Copy link

Still an issue with Mono version 5.4.0.199 (macOS) Console apps using NetStd2 libraries.

@smuellener
Copy link

smuellener commented Oct 5, 2017

Also having this issue. We force our net461 application to use Mono's fallback System.Net.Http 4.0.0 from /usr/lib/mono/4.5-api by deleting the System.Net.Http that is published with the application and changing the existing record to:

<dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

in the <app_name>.exe.config after publishing for net461 (and netstandard2.0 on the side). But this is obviously not the preferred solution. Is anyone going to fix this in Mono?

Mono version used: 5.4.0.167

@marek-safar
Copy link
Contributor

@smuellener could you please file a bug report at bugzilla.xamarin.com with repro for us to investigate further?

@stefan-schweiger
Copy link

stefan-schweiger commented Oct 13, 2017

I'm currently trying to get an ASP.Net core project targeting .NET 4.7 running and I'm getting the same error with Mono 5.4.0.201

I could probably make a repro from a clean project if anyone is interested.

@stefan-schweiger
Copy link

stefan-schweiger commented Oct 17, 2017

@marek-safar I've put the smallest repro I could come up with in this repository.

Do you still need someone to open a bug report?

Basically this is the whole code:

Program.cs

public class Program
{
    public static void Main(string[] args)
    {
        var result = new System.Net.Http.HttpClient()
            .GetAsync("https://api.ipify.org/?format=json").Result;
    }
}

TestProj.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net47</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
  </ItemGroup>
</Project>

TestProj.sln

Microsoft Visual Studio Solution File, Format Version 15.00
# Visual Studio 2017
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProj", "TestProj.csproj", "{AF0CFFD9-3273-4927-81A4-EE9A29801B42}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{AF0CFFD9-3273-4927-81A4-EE9A29801B42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{AF0CFFD9-3273-4927-81A4-EE9A29801B42}.Debug|Any CPU.Build.0 = Debug|Any CPU
	EndGlobalSection
EndGlobal

And this is basically my system information (you can see it in more detail in my repository):

Operating System
Mac OS X 10.12.6

Visual Studio Community 2017 for Mac
Version 7.2 (build 636)
Runtime: Mono 5.4.0.201 (2017-06/71277e78f6e) (64-bit)

NuGet
Version: 4.3.1.4445

.NET Core
Runtime: /usr/local/share/dotnet/dotnet
Runtime Version: 2.0.0
SDK Version: 2.0.0

MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.0/lib/mono/msbuild/15.0/bin/Sdks

@RF77
Copy link

RF77 commented Oct 23, 2017

We have the same problem.

As proposed from @marek-safar I created a bug ticket here: https://bugzilla.xamarin.com/show_bug.cgi?id=60315
I referenced this ticket and the repro project from @stefan-schweiger

@marek-safar
Copy link
Contributor

@stefan-schweiger @RF77 Thanks for the repro and bug report, will try to reproduce it locally

@stefan-schweiger
Copy link

stefan-schweiger commented Oct 30, 2017

@RF77 @marek-safar is there any reason why this issue is not viewable anymore on the xamarin bugtracker?

@marek-safar
Copy link
Contributor

Well, it's actionable on CoreFX side by stop relying on internal framework members. On Mono we have the only workaround which does patching of every version of this published NuGet for .NET Framework but as you can expect this is not a great solution

@karelz
Copy link
Member

karelz commented Sep 6, 2019

I am confused as what exactly is wrong and what are the options. This issue is pretty confusing and going in many directions over time, which is not helping :(
@marek-safar do you know which code depends on which internal Framework members?

Latest System.Net.Http package is direct copy of Framework sources to cause as few problems with .NET Framework compat as possible. I would be hesitant to take any changes to it.
Moreover we recommend to NOT use System.Net.Http package at all if possible. Ideally, that package should have never been shipped. Unfortunately we do not have a time machine to make it happen.

So, the questions are:

  • Can someone please clarify what is the root-cause here?
  • How can we address customer pain without touching System.Net.Http source code and reshipping that package?

@marek-safar
Copy link
Contributor

The details are in the original log. I didn't check if this property access is the only occurrence but it probably is not.

In more details

NuGet version of System.Net.Http targetting .NET Framework includes code in HttpMessageInvoker.SendAsync which calls System.Net.Logging.On property in System.dll assembly. The Logging is internal class https://github.com/microsoft/referencesource/blob/3b1eaf5203992df69de44c783a3eda37d3d4cd10/System/net/System/Net/Logging.cs#L23 so running this NuGet depends on the internal implementation of .NET Framework not just public API which is causing problems with Mono because it's compatible only on public API surface.

@davidsh
Copy link
Contributor

davidsh commented Sep 7, 2019

@marek-safar Thanks for the details.

In a perfect world, we would ship a new fixed version of this package. However, that is impossible now. The source code for the System.Net.Http NuGet package is built out of the release/2.0 branch which is now end-of-life. We no longer can even build a new System.Net.Http package out of the master branch. We no longer have the forked copy of the .NET Framework based System.Net.Http code in the master branch to build the .NET Framework targetted binary of System.Net.Http.dll.

The guidance we give developers now is to stop using the System.Net.Http NuGet package. It is not needed anymore because the System.Net.Http.dll binary already ships in the Microsoft.NETCore.App package. And for .NET Framework targeted applications, the one in the GAC is used.

We understand that some developers still use the package because it is either directly or indirectly used by the dependencies. For those cases, we have added tooling in Visual Studio to try to ignore the System.Net.Http.dll binary from that package and use the one from Microsoft.NETCore.App package or the GAC'd version on the machine. However, this solution is not perfect because for Mono based applications there is no sufficient tooling to do that redirection.

The summary is that this is not something we can fix unfortunately except by the magic of time. Over time, developers will use updated packages of things that no longer bring in the legacy and broken System.Net.Http NuGet package.

So, since this is not actionable anymore by CoreFx for this. We plan to close this issue.

@marek-safar
Copy link
Contributor

I think the proposal of not shipping any update to this package makes it easier for Mono to stay on top of things which is good. At the same time, it'd be helpful to mark this package as deprecated or something like that at nuget.org.

@davidsh
Copy link
Contributor

davidsh commented Sep 13, 2019

@terrajobst @ericstj Is there any way we can "mark" the NuGet package for System.Net.Http as "deprecated" or "please stop using, instead you can simply use Microsoft.NETCore.App", etc.? Can we delist the package on NuGet.org so that new applications being developed won't find it?

Or is this a "time solves all problems" kind of thing where eventually, all the upstream packages will change and stop including this package?

knocte referenced this issue in nblockchain/geewallet Dec 6, 2019
This one doesn't contain anymore the System.Net.Http dependency.
See https://github.com/dotnet/corefx/issues/19914#issuecomment-529113925
knocte referenced this issue in nblockchain/geewallet Dec 6, 2019
This one doesn't contain anymore the System.Net.Http dependency.
See https://github.com/dotnet/corefx/issues/19914#issuecomment-529113925
knocte referenced this issue in nblockchain/geewallet Dec 11, 2019
- Update NBitcoin.Altcoins too (released with NBitcoin)
- Remove Version attribute from PackageReferences of System.Net.Http
- Remove package.config references of System.Net.Http
- Remove binding redirect of System.Net.Http

The new NBitcoin version is the first version that has
System.Net.Http removed.

See https://github.com/dotnet/corefx/issues/19914#issuecomment-529113925
knocte referenced this issue in nblockchain/geewallet Dec 11, 2019
- Upgrade NBitcoin&Nethereum&JsonRpcSharp to versions that don't
depend on System.Net.Http
- Update NBitcoin.Altcoins too (released with NBitcoin)
- Remove Version attribute from PackageReferences of System.Net.Http
- Remove package.config references of System.Net.Http
- Remove binding redirect of System.Net.Http

See https://github.com/dotnet/corefx/issues/19914#issuecomment-529113925
knocte referenced this issue in nblockchain/geewallet Dec 11, 2019
- Upgrade NBitcoin&Nethereum&JsonRpcSharp to versions that don't
depend on System.Net.Http
- Update NBitcoin.Altcoins too (released with NBitcoin)
- Remove Version attribute from PackageReferences of System.Net.Http
- Remove package.config references of System.Net.Http
- Remove binding redirect of System.Net.Http

See https://github.com/dotnet/corefx/issues/19914#issuecomment-529113925

(Note: if this approach didn't work, we would see the bug's characteristic
MethodMissingException when running the integration tests that call the
update-servers Makefile target.)
knocte referenced this issue in nblockchain/geewallet Dec 12, 2019
- Upgrade NBitcoin&Nethereum&JsonRpcSharp to versions that don't
depend on System.Net.Http
- Update NBitcoin.Altcoins too (released with NBitcoin)
- Remove Version attribute from PackageReferences of System.Net.Http
- Remove package.config references of System.Net.Http
- Remove binding redirect of System.Net.Http

See https://github.com/dotnet/corefx/issues/19914#issuecomment-529113925
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 5.0 milestone Jan 31, 2020
@karelz karelz modified the milestones: 5.0, Future May 29, 2020
knocte added a commit to nblockchain/geewallet that referenced this issue Jul 30, 2020
The reason is that the new versions don't depend anymore on the
deprecated System.Net.Http nuget package. See [1] forr more info.

[1] dotnet/runtime#21777 (comment)
@teo-tsirpanis
Copy link
Contributor

Marking old packages as deprecated is tracked in dotnet/core#7420. Since updating System.Net.Http is not planned, I will close this.

@teo-tsirpanis teo-tsirpanis closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2022
@karelz karelz modified the milestones: Future, 7.0.0 Aug 7, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests