MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

MqttClientOptionsBuilder.WithTcpServer System.ArgumentException: No endpoint is set

Open ramonsmits opened this issue 1 year ago • 0 comments

Describe the bug

The MqttClientOptionsBuilder using WithTcpServer fails with the message "No endpoint is set" while RemoteEndpoint is assigned.

System.ArgumentException: No endpoint is set.
  at MQTTnet.Client.MqttClientOptionsBuilder.Build()
var options = new MqttClientOptionsBuilder()
    .WithTcpServer(s =>
    {
        s.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork;
        s.RemoteEndpoint = new DnsEndPoint(Server.Host, Server.Port);
    })
	.Build();

Doing the following works:

var options = new MqttClientOptionsBuilder()
    .WithEndPoint(new DnsEndPoint(Server.Host, Server.Port,System.Net.Sockets.AddressFamily.InterNetwork))
	.Build();

I'm not sure on the differences between these API's but I think WithTcpServer should be able to be used without WithEndPoint.

Maybe WithTcpServer is obsolete?

Which component is your bug related to?

  • Client

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of MQTTnet 4.3.6.1152
  2. Run this code, see above
  3. With these arguments, see above
  4. See error, see above

Expected behavior

Builder to succeed.

ramonsmits avatar Jul 06 '24 12:07 ramonsmits