TheTanic
TheTanic

Reputation: 1638

Setting MaxConnectionsPerServer in HttpClientHandler fails

I am creating a Xamarin.Forms application, which should run on iOS, Android and UWP.
This application uses an HttpClient to communicate with other resources. The HttpClient usage is capsulated in a .NET Standard 2.0 library. The library works fine in other application (Mainly used in a ASP.NET environment).
The library uses an instance of the HttpClientHandler to configure the HttpClient. Inside of the HttpClientHandler the sets the MaxConnectionsPerServer property to 1. This leads to an System.ArgumentException with the following informations:
Message:

"Wrong parameter r\n\r\nvalue"

StackTrace:

at Windows.Web.Http.Filters.HttpBaseProtocolFilter.put_MaxConnectionsPerServer(UInt32 value)
at System.Net.Http.HttpClientHandler.set_MaxConnectionsPerServer(Int32 value)

The rest of the fields inside the exception are null (for example ParamName, Source, ...)
The same error appears when it is used without the reference to a library.

It is easy to reproduce this error:

  1. Create a new blanc Xamarin application
  2. Add in the constructor of the MainPage the line:
    var handler = new HttpClientHandler(){ MaxConnectionsPerServer = 1};
  3. Run the application on Windows.

Am I missing any reference or incompatibility?

PS:
Xamarin.Essentials: v1.5.3.2
Xamarin.Forms: v4.8.0.1687
Microsoft.NETCore.UniversalWindowsPlattform: v6.2.10

Edit:
Referencing to the comments, my question is not clear:
The value of 1, is intended and according to the documentation, there is nothing written, that this isn't allowed. We only want a single connection per server and not more! In addition in an other environment (ASP.NET Core) the value of 1 is totaly fine and does not throw the Exception.
So why does the behaviour in Xamarin.Forms is not consistent to other environments?

Upvotes: 1

Views: 1430

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32785

Setting MaxConnectionsPerServer in HttpClientHandler fails

Please check MaxConnectionsPerServer applies to part, this property does not contain UWP platform. I'm afraid it will not work well in UWP platform. for comparing the deafferents, you could check HttpClientHandler class applies to part, it contain UWP platform.

Upvotes: 1

Related Questions