2
votes

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

3

3 Answers

5
votes

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.

2
votes

On Dotnet Core 2.1 you can try this.

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

Hope this helps.

0
votes

You can also do using MessagingFactory

MessagingFactory factory = MessagingFactory.CreateFromConnectionString(connectionString);

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