I have a simple class that I want to use to create a queue on my Azure service bus namespace. here's my class:
public class ServiceBusPublisher
{
private readonly string _connString;
public ServiceBusPublisher(IConfiguration config)
{
_connString = config.GetSection("ServiceBus:Endpoint").Value;
}
public void CreateQueue(string queueName)
{
var namespaceManager = NamespaceManager.CreateFromConnectionString(_connString);
if (!namespaceManager.QueueExists(queueName))
{
namespaceManager.CreateQueue(queueName);
}
}
}
Everything is setup and seems to be working, I registered the service in my Startup, and my connection string comes through fine, as the service bus connection string:
Endpoint=sb://myservicebus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abcdefg12345
But when it tries to call NamespaceManager.CreateFromConnectionString(_connString)
, I get this exception
System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. File name: 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' at Microsoft.ServiceBus.Messaging.Configuration.KeyValueConfigurationManager.CreateNameValueCollectionFromConnectionString(String connectionString) at Microsoft.ServiceBus.Messaging.Configuration.KeyValueConfigurationManager.Initialize(String connection, Nullable`1 transportType) at Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(String connectionString)
I feel like I'm crazy because this should be so simple, but it seems like it's trying to access the configuration file, and it can't. But I'm already passing it the connection string, so I'm not sure why it's doing that.
Am I doing something wrong?