mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-31 03:02:39 +08:00
Moved check on Options.ValidateFeatures below ThrowIf methods to prevent NullReferenceException (#1800)
* Moved check on Options.ValidateFeatures below ThrowIf methods to prevent NullReferenceException * Add Unit Test * Update ReleaseNotes.md --------- Co-authored-by: Christian <6939810+chkr1011@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
* [Client] Fixed _PlatformNotSupportedException_ when using Blazor (#1755, thanks to @Nickztar).
|
* [Client] Fixed _PlatformNotSupportedException_ when using Blazor (#1755, thanks to @Nickztar).
|
||||||
|
* [Client] Fixed _NullReferenceException_ when performing several actions when not connected (#1800, thanks to @ramonsmits).
|
||||||
* [Server] Fixed _NullReferenceException_ in retained messages management (#1762, thanks to @logicaloud).
|
* [Server] Fixed _NullReferenceException_ in retained messages management (#1762, thanks to @logicaloud).
|
||||||
* [Server] Exposed new option which allows disabling packet fragmentation (#1753).
|
* [Server] Exposed new option which allows disabling packet fragmentation (#1753).
|
||||||
* [Server] Expired sessions will no longer be used when a client connects (#1756).
|
* [Server] Expired sessions will no longer be used when a client connects (#1756).
|
||||||
|
|||||||
@@ -196,5 +196,27 @@ namespace MQTTnet.Tests.Clients.MqttClient
|
|||||||
Assert.AreEqual(response.UserProperties[0].Value, "Value");
|
Assert.AreEqual(response.UserProperties[0].Value, "Value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task Throw_Proper_Exception_When_Not_Connected()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var mqttFactory = new MqttFactory();
|
||||||
|
using (var mqttClient = mqttFactory.CreateMqttClient())
|
||||||
|
{
|
||||||
|
await mqttClient.SubscribeAsync("test", MqttQualityOfServiceLevel.AtLeastOnce);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (MqttCommunicationException exception)
|
||||||
|
{
|
||||||
|
if (exception.Message == "The client is not connected.")
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Fail();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,14 +321,14 @@ namespace MQTTnet.Client
|
|||||||
MqttTopicValidator.ThrowIfInvalidSubscribe(topicFilter.Topic);
|
MqttTopicValidator.ThrowIfInvalidSubscribe(topicFilter.Topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ThrowIfDisposed();
|
||||||
|
ThrowIfNotConnected();
|
||||||
|
|
||||||
if (Options.ValidateFeatures)
|
if (Options.ValidateFeatures)
|
||||||
{
|
{
|
||||||
MqttClientSubscribeOptionsValidator.ThrowIfNotSupported(options, _adapter.PacketFormatterAdapter.ProtocolVersion);
|
MqttClientSubscribeOptionsValidator.ThrowIfNotSupported(options, _adapter.PacketFormatterAdapter.ProtocolVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
ThrowIfDisposed();
|
|
||||||
ThrowIfNotConnected();
|
|
||||||
|
|
||||||
var subscribePacket = MqttPacketFactories.Subscribe.Create(options);
|
var subscribePacket = MqttPacketFactories.Subscribe.Create(options);
|
||||||
subscribePacket.PacketIdentifier = _packetIdentifierProvider.GetNextPacketIdentifier();
|
subscribePacket.PacketIdentifier = _packetIdentifierProvider.GetNextPacketIdentifier();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user