Skip to content

Commit 98aca03

Browse files
Fix NullReferenceException when adding certificates to HttpClient due to uninitialized handler.SslOptions.ClientCertificates (#1053)
1 parent 14f87e0 commit 98aca03

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,20 @@ private static SocketsHttpHandler GetHandler(Uri URI, ArrayList authCollection,
238238
{
239239
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
240240
}
241-
foreach (X509Certificate2 cert in certificateCollection)
242-
handler.SslOptions.ClientCertificates.Add(cert);
241+
if (certificateCollection.Count > 0)
242+
{
243+
if (handler.SslOptions.ClientCertificates == null)
244+
{
245+
handler.SslOptions.ClientCertificates = new X509CertificateCollection(certificateCollection);
246+
}
247+
else
248+
{
249+
foreach (X509Certificate2 cert in certificateCollection)
250+
{
251+
handler.SslOptions.ClientCertificates.Add(cert);
252+
}
253+
}
254+
}
243255

244256
WebProxy proxy = getProxy(proxyHost, proxyPort, authProxyCollection);
245257
if (proxy != null)

0 commit comments

Comments
 (0)