I used MQTTnet library to connect to my server via TLS/SSL protocol but there was one issue related to configuration for MqttClientOptionsBuilderTlsParameters Class like this:
"Cannot implicitly convert type 'System.Collections.Generic.List<System.Security.Cryptography.X509Certificates.X509Certificate>' to 'System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable<byte>>'. An explicit conversion exists (are you missing a cast?)"
My code is:
var caCert = X509Certificate.CreateFromCertFile(@"certificate.crt");
var clientCert = new X509Certificate2(@"certificate.pfx", "12345678");
var tlsOptions = new MqttClientOptionsBuilderTlsParameters
{
UseTls = true,
Certificates = new List<X509Certificate>
{
caCert, clientCert
},
IgnoreCertificateRevocationErrors = true,
IgnoreCertificateChainErrors = true,
AllowUntrustedCertificates = true,
SslProtocol = System.Security.Authentication.SslProtocols.Tls12
};
Mistake exactly located in "List<X509Certificate>"
Whether the reason is version of MQTTnet? I am using MQTTnet v3.0.5
I followed "TLS using a client certificate" item in link https://github.com/dotnet/MQTTnet/wiki/Client#certificate-based-authentication but perhaps it cannot help me to solve this problem.
Pls help me to check and solve it. Thanks a lot.
Update: I had upgraded MQTTnet to version 3.1.1 and the problem was solved - Maybe it's a common version for almost applications that still had used version 3.