diff --git a/Source/MQTTnet/Client/MqttClient.cs b/Source/MQTTnet/Client/MqttClient.cs index f037d6622..9dd7cb955 100644 --- a/Source/MQTTnet/Client/MqttClient.cs +++ b/Source/MQTTnet/Client/MqttClient.cs @@ -72,7 +72,9 @@ public async Task ConnectAsync(IMqttClientOptions ThrowIfDisposed(); if (CompareExchangeConnectionStatus(MqttClientConnectionStatus.Connecting, MqttClientConnectionStatus.Disconnected) != MqttClientConnectionStatus.Disconnected) + { throw new InvalidOperationException("Not allowed to connect while connect/disconnect is pending."); + } MqttClientAuthenticateResult authenticateResult = null; @@ -734,8 +736,10 @@ async Task PublishAtMostOnce(MqttPublishPacket publishP async Task PublishAtLeastOnceAsync(MqttPublishPacket publishPacket, CancellationToken cancellationToken) { publishPacket.PacketIdentifier = _packetIdentifierProvider.GetNextPacketIdentifier(); - var response = await SendAndReceiveAsync(publishPacket, cancellationToken).ConfigureAwait(false); - return _adapter.PacketFormatterAdapter.DataConverter.CreateClientPublishResult(response); + + var pubAckPacket = await SendAndReceiveAsync(publishPacket, cancellationToken).ConfigureAwait(false); + + return _adapter.PacketFormatterAdapter.DataConverter.CreateClientPublishResult(pubAckPacket); } async Task PublishExactlyOnceAsync(MqttPublishPacket publishPacket, CancellationToken cancellationToken)