dotnet / dotnet/MQTTnet

MqttClientOptionsBuilder.WithTcpServer:The “_remoteEndPoint” is missing instantiation

Open
#2,010 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
C#
Stars
5.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

### Which component is your bug related to?
- ManagedClient

### To Reproduce
Steps to reproduce the behavior:
1. Using this version of MQTTnet '**Lastest**'.
2. Run this code '....'.
```csharp
var mqttClientOptions = new MqttClientOptionsBuilder()
.WithTcpServer(tcpOptions =>
{
tcpOptions.RemoteEndpoint = new DnsEndPoint(Host, Port);
tcpOptions.Server = Host;
tcpOptions.Port = Port;
tcpOptions.BufferSize = 0x100000;
});

var managed = new ManagedMqttClientOptionsBuilder()
.WithClientOptions(mqttClientOptions).Build();
```
5. See error.
**"No endpoint is set."**

### Fix
ADD these code to class ‘ MQTTnet.Client.MqttClientOptionsBuilder’

**_remoteEndPoint = new DnsEndPoint(_tcpOptions.Server, _tcpOptions.Port ?? 0, _tcpOptions.AddressFamily);**

```csharp
public MqttClientOptionsBuilder WithTcpServer(Action optionsBuilder)
{
if (optionsBuilder == null)
{
throw new ArgumentNullException(nameof(optionsBuilder));
}

_tcpOptions = new MqttClientTcpOptions();
optionsBuilder.Invoke(_tcpOptions);
_remoteEndPoint = new DnsEndPoint(_tcpOptions.Server, _tcpOptions.Port ?? 0, _tcpOptions.AddressFamily);
return this;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.