Failure to connect to Azure Service bus queue

Am trying to listen to an azure service bus queue but am getting an exception when initializing the connection to to the queue. I have tried to search for a way out but with less success. Note that am using .NETCore 2.1. This is how am initializing the connection it:

// Initialize the connection to Service Bus Queue
_queueClient = QueueClient.CreateFromConnectionString(_interswitchQueueConnectionString, _interswitchQueueName, ReceiveMode.ReceiveAndDelete);

And this the exception am getting:

System.TypeInitializationException: The type initializer for 'Microsoft.ServiceBus.Messaging.Constants' threw an exception. ---> System.TypeLoadException: Could not load type 'System.UriTemplate' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. at Microsoft.ServiceBus.Messaging.Constants..cctor() --- End of inner exception stack trace --- at Microsoft.ServiceBus.ServiceBusConnectionStringBuilder..ctor() at Microsoft.ServiceBus.Messaging.QueueClient.CreateFromConnectionString(String connectionString, String path, ReceiveMode mode)

The same initialization works fine when using .net framework. How can I do it in .NetCore ? Please Help Thanks in advance

Upvotes: 2

Views: 5187

Answers (3)

Sean Feldman
Sean Feldman

Reputation: 26057

With .NET Core you should use the new .NET Standard Azure Service Bus client, Microsoft.Azure.ServiceBus. The old client WindowsAzure.ServiceBus is a legacy client, only works with Full Framework, and is not recommended moving forward.

The new client does not have a concept of factory. You're in charge of creating entity clients (QueueClient, SubscriptionClient, and TopicClient) and managing connections.

Upvotes: 5

Yuvaranjani
Yuvaranjani

Reputation: 310

You can also do using MessagingFactory

MessagingFactory factory = MessagingFactory.CreateFromConnectionString(connectionString);

            queueClient = await factory.CreateMessageReceiverAsync(_entityPath, ReceiveMode.ReceiveAndDelete);

Upvotes: 0

Mohammed Kamran Azam
Mohammed Kamran Azam

Reputation: 289

On Dotnet Core 2.1 you can try this.

var queueClient = new QueueClient(connectionString, entityPath, ReceiveMode.ReceiveAndDelete);

Hope this helps.

Upvotes: 2

Related Questions