From 7fe7137ff9715254be083115e29685d4c9f1aabd Mon Sep 17 00:00:00 2001 From: Steve Bjorg Date: Thu, 17 Sep 2020 08:54:24 -0700 Subject: [PATCH] check if running in WebAssembly instead of catching PlatformNotSupportedException --- .../Websocket/GraphQLHttpWebSocket.cs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs b/src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs index 2f4a86f4..aba35e8f 100644 --- a/src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs +++ b/src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs @@ -408,22 +408,12 @@ public Task InitializeWebSocket() #else _clientWebSocket = new ClientWebSocket(); _clientWebSocket.Options.AddSubProtocol("graphql-ws"); - try + if(!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Create("WEBASSEMBLY"))) { + // the following properties are not supported in Blazor WebAssembly and throw a PlatformNotSupportedException error when accessed _clientWebSocket.Options.ClientCertificates = ((HttpClientHandler)Options.HttpMessageHandler).ClientCertificates; - } - catch (PlatformNotSupportedException) - { - Debug.WriteLine("unable to set Options.ClientCertificates property; platform does not support it"); - } - try - { _clientWebSocket.Options.UseDefaultCredentials = ((HttpClientHandler)Options.HttpMessageHandler).UseDefaultCredentials; } - catch (PlatformNotSupportedException) - { - Debug.WriteLine("unable to set Options.UseDefaultCredentials property; platform does not support it"); - } Options.ConfigureWebsocketOptions(_clientWebSocket.Options); #endif return _initializeWebSocketTask = ConnectAsync(_internalCancellationToken); @@ -627,7 +617,7 @@ public void Complete() /// /// Task to await the completion (a.k.a. disposal) of this websocket. - /// + /// /// Async disposal as recommended by Stephen Cleary (https://blog.stephencleary.com/2013/03/async-oop-6-disposal.html) public Task? Completion { get; private set; }