diff --git a/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs b/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs index 59f1c9a..dc57e40 100644 --- a/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs +++ b/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs @@ -387,7 +387,10 @@ namespace MQTTnet.Extensions.ManagedClient //removed it, in which case we don't want to do anything. _messageQueue.RemoveFirst(i => i.Id.Equals(message.Id)); } - _storageManager?.RemoveAsync(message).GetAwaiter().GetResult(); + if (_storageManager != null) + { + _storageManager.RemoveAsync(message).GetAwaiter().GetResult(); + } } catch (MqttCommunicationException exception) { @@ -408,6 +411,10 @@ namespace MQTTnet.Extensions.ManagedClient { _messageQueue.RemoveFirst(i => i.Id.Equals(message.Id)); } + if (_storageManager != null) + { + _storageManager.RemoveAsync(message).GetAwaiter().GetResult(); + } } } catch (Exception exception)