Reputation: 1638
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:
MainPage
the line:var handler = new HttpClientHandler(){ MaxConnectionsPerServer = 1};
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
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