1

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.

Trang Phan
  • 11
  • 2
  • 1
    Look closely at the example you have linked to, it is not the same as the code you have posted, you appear to be missing `()` – hardillb Nov 14 '22 at 11:27
  • I also thought like that, but it's not bro. I tried to upgrade to latest version of MQTTnet and this issue was solved, but almost the other class in my code had trouble, so I decided to keep this old version. Are there any suggestion? Pls help me. The document of MQTTnet also mentions that it's support for v3, but reality it didnt work... – Trang Phan Nov 17 '22 at 05:02

0 Answers0