diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/api/Azure.Messaging.ServiceBus.netstandard2.0.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/api/Azure.Messaging.ServiceBus.netstandard2.0.cs
index bbe11db810330..561c02ef39072 100644
--- a/sdk/servicebus/Azure.Messaging.ServiceBus/api/Azure.Messaging.ServiceBus.netstandard2.0.cs
+++ b/sdk/servicebus/Azure.Messaging.ServiceBus/api/Azure.Messaging.ServiceBus.netstandard2.0.cs
@@ -130,20 +130,19 @@ public ServiceBusException(string message, Azure.Messaging.ServiceBus.ServiceBus
public enum FailureReason
{
GeneralError = 0,
- ClientClosed = 1,
- MessagingEntityNotFound = 2,
- MessageLockLost = 3,
- MessageNotFound = 4,
- MessageSizeExceeded = 5,
- MessagingEntityDisabled = 6,
- QuotaExceeded = 7,
- ServiceBusy = 8,
- ServiceTimeout = 9,
- ServiceCommunicationProblem = 10,
- SessionCannotBeLocked = 11,
- SessionLockLost = 12,
- Unauthorized = 13,
- MessagingEntityAlreadyExists = 14,
+ MessagingEntityNotFound = 1,
+ MessageLockLost = 2,
+ MessageNotFound = 3,
+ MessageSizeExceeded = 4,
+ MessagingEntityDisabled = 5,
+ QuotaExceeded = 6,
+ ServiceBusy = 7,
+ ServiceTimeout = 8,
+ ServiceCommunicationProblem = 9,
+ SessionCannotBeLocked = 10,
+ SessionLockLost = 11,
+ Unauthorized = 12,
+ MessagingEntityAlreadyExists = 13,
}
}
public partial class ServiceBusMessage
diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpClient.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpClient.cs
index 8a3d5f24b0b8a..a055a9b500e0c 100644
--- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpClient.cs
+++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpClient.cs
@@ -120,7 +120,7 @@ public override TransportSender CreateSender(
ServiceBusRetryPolicy retryPolicy,
string identifier)
{
- Argument.AssertNotClosed(_closed, nameof(AmqpClient));
+ Argument.AssertNotDisposed(_closed, nameof(AmqpClient));
return new AmqpSender
(
@@ -156,7 +156,7 @@ public override TransportReceiver CreateReceiver(
string sessionId,
bool isSessionReceiver)
{
- Argument.AssertNotClosed(_closed, nameof(AmqpClient));
+ Argument.AssertNotDisposed(_closed, nameof(AmqpClient));
return new AmqpReceiver
(
@@ -186,7 +186,7 @@ public override TransportRuleManager CreateRuleManager(
ServiceBusRetryPolicy retryPolicy,
string identifier)
{
- Argument.AssertNotClosed(_closed, nameof(AmqpClient));
+ Argument.AssertNotDisposed(_closed, nameof(AmqpClient));
return new AmqpRuleManager
(
diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Core/Argument.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Core/Argument.cs
index 9d21195096cf6..db71e68352013 100644
--- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Core/Argument.cs
+++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Core/Argument.cs
@@ -134,25 +134,6 @@ public static void AssertNotDisposed(bool wasDisposed, string targetName)
}
}
- ///
- /// Ensures that an instance has not been closed, throwing an
- /// if that invariant is not met.
- ///
- ///
- /// true if the target instance has been closed; otherwise, false.
- /// The name of the target instance that is being verified.
- ///
- public static void AssertNotClosed(bool wasClosed, string targetName)
- {
- if (wasClosed)
- {
- throw new ServiceBusException(
- string.Format(CultureInfo.CurrentCulture, Resources.ClosedInstanceCannotPerformOperation, targetName),
- ServiceBusException.FailureReason.ClientClosed,
- targetName);
- }
- }
-
///
/// Ensures that an argument's value is a well-formed Service Bus fully qualified namespace value,
/// throwing a if that invariant is not met.
diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Primitives/ServiceBusException.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Primitives/ServiceBusException.cs
index 27a58b9a46057..41b0e81f3b758 100644
--- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Primitives/ServiceBusException.cs
+++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Primitives/ServiceBusException.cs
@@ -135,11 +135,6 @@ public enum FailureReason
/// The exception was the result of a general error within the client library.
GeneralError,
- /// An operation has been attempted using an Service Bus client instance
- /// which has already been closed.
- ///
- ClientClosed,
-
/// A Service Bus resource cannot be found by the Service Bus service.
MessagingEntityNotFound,
diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Receiver/ServiceBusReceiver.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Receiver/ServiceBusReceiver.cs
index 6dc57880022b8..9b2aa5a672f4d 100644
--- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Receiver/ServiceBusReceiver.cs
+++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Receiver/ServiceBusReceiver.cs
@@ -190,7 +190,7 @@ public virtual async Task> ReceiveMessa
CancellationToken cancellationToken = default)
{
Argument.AssertAtLeast(maxMessages, 1, nameof(maxMessages));
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusReceiver));
if (maxWaitTime.HasValue)
{
Argument.AssertPositive(maxWaitTime.Value, nameof(maxWaitTime));
@@ -375,7 +375,7 @@ private async Task> PeekMessagesInterna
int maxMessages,
CancellationToken cancellationToken)
{
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusReceiver));
cancellationToken.ThrowIfCancellationRequested();
Logger.PeekMessageStart(Identifier, sequenceNumber, maxMessages);
using DiagnosticScope scope = ScopeFactory.CreateScope(
@@ -452,7 +452,7 @@ public virtual async Task CompleteMessageAsync(
CancellationToken cancellationToken = default)
{
ThrowIfLockTokenIsEmpty(lockToken);
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusReceiver));
Argument.AssertNotNullOrEmpty(lockToken, nameof(lockToken));
ThrowIfNotPeekLockMode();
cancellationToken.ThrowIfCancellationRequested();
@@ -529,7 +529,7 @@ public virtual async Task AbandonMessageAsync(
CancellationToken cancellationToken = default)
{
ThrowIfLockTokenIsEmpty(lockToken);
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusReceiver));
ThrowIfNotPeekLockMode();
cancellationToken.ThrowIfCancellationRequested();
Logger.AbandonMessageStart(Identifier, 1, lockToken);
@@ -688,7 +688,7 @@ private async Task DeadLetterInternalAsync(
CancellationToken cancellationToken = default)
{
ThrowIfLockTokenIsEmpty(lockToken);
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusReceiver));
cancellationToken.ThrowIfCancellationRequested();
ThrowIfNotPeekLockMode();
Logger.DeadLetterMessageStart(Identifier, 1, lockToken);
@@ -768,7 +768,7 @@ public virtual async Task DeferMessageAsync(
CancellationToken cancellationToken = default)
{
ThrowIfLockTokenIsEmpty(lockToken);
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusReceiver));
ThrowIfNotPeekLockMode();
cancellationToken.ThrowIfCancellationRequested();
Logger.DeferMessageStart(Identifier, 1, lockToken);
@@ -848,7 +848,7 @@ public virtual async Task> ReceiveDefer
IEnumerable sequenceNumbers,
CancellationToken cancellationToken = default)
{
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusReceiver));
Argument.AssertNotNullOrEmpty(sequenceNumbers, nameof(sequenceNumbers));
cancellationToken.ThrowIfCancellationRequested();
var sequenceNumbersList = sequenceNumbers.ToList();
@@ -921,7 +921,7 @@ public virtual async Task RenewMessageLockAsync(
CancellationToken cancellationToken = default)
{
ThrowIfLockTokenIsEmpty(lockToken);
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusReceiver));
ThrowIfNotPeekLockMode();
ThrowIfSessionReceiver();
cancellationToken.ThrowIfCancellationRequested();
diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Receiver/ServiceBusSessionReceiver.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Receiver/ServiceBusSessionReceiver.cs
index 603540e0d0490..259574b7209d6 100644
--- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Receiver/ServiceBusSessionReceiver.cs
+++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Receiver/ServiceBusSessionReceiver.cs
@@ -98,7 +98,7 @@ protected ServiceBusSessionReceiver() : base() { }
/// The session state as byte array.
public virtual async Task GetSessionStateAsync(CancellationToken cancellationToken = default)
{
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSessionReceiver));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusSessionReceiver));
cancellationToken.ThrowIfCancellationRequested();
Logger.GetSessionStateStart(Identifier, SessionId);
using DiagnosticScope scope = ScopeFactory.CreateScope(
@@ -137,7 +137,7 @@ public virtual async Task SetSessionStateAsync(
byte[] sessionState,
CancellationToken cancellationToken = default)
{
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSessionReceiver));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusSessionReceiver));
cancellationToken.ThrowIfCancellationRequested();
Logger.SetSessionStateStart(Identifier, SessionId);
using DiagnosticScope scope = ScopeFactory.CreateScope(
@@ -177,7 +177,7 @@ public virtual async Task SetSessionStateAsync(
///
public virtual async Task RenewSessionLockAsync(CancellationToken cancellationToken = default)
{
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSessionReceiver));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusSessionReceiver));
cancellationToken.ThrowIfCancellationRequested();
Logger.RenewSessionLockStart(Identifier, SessionId);
using DiagnosticScope scope = ScopeFactory.CreateScope(
diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/RuleManager/ServiceBusRuleManager.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/RuleManager/ServiceBusRuleManager.cs
index 6b8898299f230..d987c1d5afdd3 100644
--- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/RuleManager/ServiceBusRuleManager.cs
+++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/RuleManager/ServiceBusRuleManager.cs
@@ -120,7 +120,7 @@ public virtual async Task AddRuleAsync(
RuleDescription description,
CancellationToken cancellationToken = default)
{
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusRuleManager));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusRuleManager));
Argument.AssertNotNull(description, nameof(description));
cancellationToken.ThrowIfCancellationRequested();
EntityNameFormatter.CheckValidRuleName(description.Name);
@@ -154,7 +154,7 @@ public virtual async Task RemoveRuleAsync(
string ruleName,
CancellationToken cancellationToken = default)
{
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusRuleManager));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusRuleManager));
Argument.AssertNotNullOrEmpty(ruleName, nameof(ruleName));
cancellationToken.ThrowIfCancellationRequested();
ServiceBusEventSource.Log.RemoveRuleStart(Identifier, ruleName);
@@ -185,7 +185,7 @@ await InnerRuleManager.RemoveRuleAsync(
public virtual async Task> GetRulesAsync(CancellationToken cancellationToken = default)
{
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusRuleManager));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusRuleManager));
cancellationToken.ThrowIfCancellationRequested();
ServiceBusEventSource.Log.GetRuleStart(Identifier);
IList rulesDescription;
diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Sender/ServiceBusSender.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Sender/ServiceBusSender.cs
index 6744066dc1def..b8e113cc8483b 100755
--- a/sdk/servicebus/Azure.Messaging.ServiceBus/src/Sender/ServiceBusSender.cs
+++ b/sdk/servicebus/Azure.Messaging.ServiceBus/src/Sender/ServiceBusSender.cs
@@ -180,7 +180,7 @@ public virtual async Task SendMessagesAsync(
CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(messages, nameof(messages));
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSender));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusSender));
IList messageList = messages.ToList();
if (messageList.Count == 0)
{
@@ -308,7 +308,7 @@ public virtual async ValueTask CreateMessageBatchAsync(
CreateMessageBatchOptions options,
CancellationToken cancellationToken = default)
{
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSender));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusSender));
options = options?.Clone() ?? new CreateMessageBatchOptions();
cancellationToken.ThrowIfCancellationRequested();
Logger.CreateMessageBatchStart(Identifier);
@@ -343,7 +343,7 @@ public virtual async Task SendMessagesAsync(
CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(messageBatch, nameof(messageBatch));
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSender));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusSender));
cancellationToken.ThrowIfCancellationRequested();
Logger.SendMessageStart(Identifier, messageBatch.Count);
using DiagnosticScope scope = CreateDiagnosticScope(
@@ -425,7 +425,7 @@ public virtual async Task ScheduleMessagesAsync(
CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(messages, nameof(messages));
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSender));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusSender));
cancellationToken.ThrowIfCancellationRequested();
var messageList = messages.ToList();
await ApplyPlugins(messageList).ConfigureAwait(false);
@@ -483,7 +483,7 @@ public virtual async Task CancelScheduledMessagesAsync(
IEnumerable sequenceNumbers,
CancellationToken cancellationToken = default)
{
- Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSender));
+ Argument.AssertNotDisposed(IsDisposed, nameof(ServiceBusSender));
cancellationToken.ThrowIfCancellationRequested();
var sequenceNumberList = sequenceNumbers.ToArray();
Logger.CancelScheduledMessagesStart(Identifier, sequenceNumberList);
diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Sender/SenderLiveTests.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Sender/SenderLiveTests.cs
index 2d218dfa5cf45..09f53fa3cee72 100644
--- a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Sender/SenderLiveTests.cs
+++ b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Sender/SenderLiveTests.cs
@@ -223,10 +223,9 @@ public async Task CloseSenderShouldNotCloseConnection()
var sequenceNum = await sender.ScheduleMessageAsync(GetMessage(), scheduleTime);
await sender.DisposeAsync(); // shouldn't close connection, but should close send link
- Assert.That(async () => await sender.SendMessageAsync(GetMessage()),
- Throws.InstanceOf().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.ClientClosed));
- Assert.That(async () => await sender.ScheduleMessageAsync(GetMessage(), default), Throws.InstanceOf().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.ClientClosed));
- Assert.That(async () => await sender.CancelScheduledMessageAsync(sequenceNum), Throws.InstanceOf().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.ClientClosed));
+ Assert.That(async () => await sender.SendMessageAsync(GetMessage()), Throws.InstanceOf());
+ Assert.That(async () => await sender.ScheduleMessageAsync(GetMessage(), default), Throws.InstanceOf());
+ Assert.That(async () => await sender.CancelScheduledMessageAsync(sequenceNum), Throws.InstanceOf());
// receive should still work
await using var receiver = client.CreateReceiver(scope.QueueName);