azureazureservicebusazure-servicebus-subscriptions

Azure Service Bus: The connection string used for an Service Bus client must specify the Service Bus namespace host and either a Shared Access Key


Why is my RootManageSharedAccessKey Connection String Invalid?

Code:

When executing the code below, I receive an error about an invalid connection string:

serviceBusClient <- new ServiceBusClient(connectionString)

Error:

System.NotImplementedException: 'The method or operation is not implemented.'

System.ArgumentException: 'The connection string used for an Service Bus client must specify the Service Bus namespace host and either a Shared Access Key (both the name and value) OR a Shared Access Signature to be valid. Parameter name: connectionString'

enter image description here

ConnectionString:

"Endpoint=sb://myNameSpace.servicebus.windows.net/;TransportType=AmqpWebSockets;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=*******************************************="

I also tried removing the TransportType property from the connection string:

"Endpoint=sb://myNameSpace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=*******************************************="

The connection string was derived from the Shared Access Policy of my Service Bus resource:

enter image description here

Context:

Xamarin.Forms (Android)

Azure.Messaging.ServiceBus

NuGet Packages:

Azure.Messaging.ServiceBus (7.11.1) Xamarin.Forms (5.0.0.2545)


Solution

  • For those who may be interested, the root cause of this turned out to be that the connection string passed to ServiceBusClient was JSON-encoded, causing two quote literals to be embedded. As a result, there was no Endpoint= token present (it was "Endpoint=) which left the client unable to determine where to connect to.