Skip to content

Commit a73ae50

Browse files
System.Security.Cryptography fails on WASM (#25285)
1 parent 8066290 commit a73ae50

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/SignalR/clients/csharp/Http.Connections.Client/src/HttpConnectionFactory.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ public async ValueTask<ConnectionContext> ConnectAsync(EndPoint endPoint, Cancel
8282
// Internal for testing
8383
internal static HttpConnectionOptions ShallowCopyHttpConnectionOptions(HttpConnectionOptions options)
8484
{
85-
return new HttpConnectionOptions
85+
var newOptions = new HttpConnectionOptions
8686
{
8787
HttpMessageHandlerFactory = options.HttpMessageHandlerFactory,
8888
Headers = options.Headers,
89-
ClientCertificates = options.ClientCertificates,
9089
Cookies = options.Cookies,
9190
Url = options.Url,
9291
Transports = options.Transports,
@@ -99,6 +98,14 @@ internal static HttpConnectionOptions ShallowCopyHttpConnectionOptions(HttpConne
9998
DefaultTransferFormat = options.DefaultTransferFormat,
10099
WebSocketConfiguration = options.WebSocketConfiguration,
101100
};
101+
102+
// WASM doesn't support Crypto APIs and our setter throws if you try to assign null
103+
if (options.ClientCertificates != null)
104+
{
105+
newOptions.ClientCertificates = options.ClientCertificates;
106+
}
107+
108+
return newOptions;
102109
}
103110
}
104111
}

src/SignalR/clients/csharp/Http.Connections.Client/src/HttpConnectionOptions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Threading;
1111
using System.Threading.Tasks;
1212
using Microsoft.AspNetCore.Connections;
13+
using Microsoft.AspNetCore.Http.Connections.Client.Internal;
1314

1415
namespace Microsoft.AspNetCore.Http.Connections.Client
1516
{
@@ -28,7 +29,13 @@ public class HttpConnectionOptions
2829
public HttpConnectionOptions()
2930
{
3031
_headers = new Dictionary<string, string>();
31-
_clientCertificates = new X509CertificateCollection();
32+
33+
// System.Security.Cryptography isn't supported on WASM currently
34+
if (!Utils.IsRunningInBrowser())
35+
{
36+
_clientCertificates = new X509CertificateCollection();
37+
}
38+
3239
_cookies = new CookieContainer();
3340

3441
Transports = HttpTransports.All;

0 commit comments

Comments
 (0)