ServiceStack / Issues

Issue Tracker for the commercial versions of ServiceStack
11 stars 8 forks source link

ServerEventsClient.cs Start Method using Send throws PlattformNotSupported Exception (on Mobile Platform) #787

Closed oezyurt closed 1 year ago

oezyurt commented 1 year ago

Describe the issue

in our Android/iOS Core Net6 Project the method ServerEventsClient.Connect() throw an exception "PlattformNotSupported"

client = new ServerEventsClient(this.BaseUri);
await client.Connect();

   at System.Net.Http.HttpClientHandler.Send(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpMessageInvoker.Send(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.Send(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)

Reproduction

This ServiceStack code throw the exeception in class ServerEventsClient

2023-01-23_13h07_34

We implemented a Workaround that's work, but... (Invoke Custom HttpClientHandler that override the Send Method)

client = new ServerEventsClient(this.BaseUri)
      {
          HttpClientHandlerFactory = (x) => { return this.HttpClientHandlerFactory?.Invoke(); },
      }
....
    internal class ServiceStackHttpClientHandler : HttpClientHandler
    {
        public ServiceStackHttpClientHandler()
        {
        }

        protected override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var task = this.SendAsync(request, cancellationToken);
            return task.GetAwaiter().GetResult();
        }
    }

in Android this workaround fire Warnings ...

Core6 throwing the Exception here:

https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.cs

2023-01-30_19h09_04

Expected behavior

Please Fix the issue for Mobile Core Net6

System Info

Visual Studio 22
ServiceStack v6.5

Additional context

No response

Validations

mythz commented 1 year ago

I've added an async StartAsync() overload in this commit which is now available in the latest v6.5.1+ on MyGet.

Can you try to see if using the new non-blocking StartAsync() method resolves this issue.

oezyurt commented 1 year ago

Thx, I think the ReStart Method includes the same issue ... the OnExceptionReceived Event includes the Restart()

mythz commented 1 year ago

I've updated .NET 6+ clients to call StartAsync() on Restart in this commit, this change is now available on MyGet, you'll need to clear your NuGet packages cache to download the latest version.

oezyurt commented 1 year ago

Thx, i can confirm your commit fix the issue for me