diff --git a/Source/MQTTnet/Client/Options/MqttClientCaFileCertificateValidationHandler.cs b/Source/MQTTnet/Client/Options/MqttClientCaFileCertificateValidationHandler.cs index 2db41a0fb..60fce664b 100644 --- a/Source/MQTTnet/Client/Options/MqttClientCaFileCertificateValidationHandler.cs +++ b/Source/MQTTnet/Client/Options/MqttClientCaFileCertificateValidationHandler.cs @@ -20,7 +20,7 @@ internal static bool Handle(MqttClientCertificateValidationEventArgs cvArgs) if (cvArgs.SslPolicyErrors == System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) { string caFile = cvArgs.ClientOptions.TlsOptions.CaFile; - if (!string.IsNullOrEmpty(caFile) && File.Exists(caFile)) + if (!string.IsNullOrEmpty(caFile)) { X509Certificate2Collection caCerts = new X509Certificate2Collection(); #if NET6_0_OR_GREATER diff --git a/Source/MQTTnet/Client/Options/MqttClientTlsOptionsBuilder.cs b/Source/MQTTnet/Client/Options/MqttClientTlsOptionsBuilder.cs index 5dc5d96ac..8da97bbc2 100644 --- a/Source/MQTTnet/Client/Options/MqttClientTlsOptionsBuilder.cs +++ b/Source/MQTTnet/Client/Options/MqttClientTlsOptionsBuilder.cs @@ -144,8 +144,8 @@ public MqttClientTlsOptionsBuilder WithCaFile(string caFile) { throw new InvalidOperationException("WithCaFile cannot be used with a custom Certificate Validation Handler"); } - WithCertificateValidationHandler(MqttClientCaFileCertificateValidationHandler.Handle); _tlsOptions.CaFile = caFile; + WithCertificateValidationHandler(MqttClientCaFileCertificateValidationHandler.Handle); return this; } #endif