Foundatio.AzureServiceBus
Foundatio.AzureServiceBus copied to clipboard
NullReference Exception on Enqueuing
It seems that commit fe221fbf89deef8841cc3a92d00f79b66b81bcbe from April inserted a bug into the code. Now a simple
await _queueClient.EnqueueAsync(message);
will throw an exception. The problem is at AzureServiceBusQueue.cs (114)
foreach (var property in options.Properties)
brokeredMessage.UserProperties[property.Key] = property.Value;
The problem is, unless options are explicitly set, the Properties property is null.
The proper fix, I believe, is to change IQueue.cs(69) from
public class QueueEntryOptions {
public string CorrelationId { get; set; }
public DataDictionary Properties { get; set; }
}
to
public class QueueEntryOptions {
public string CorrelationId { get; set; }
public DataDictionary Properties { get; set; } = new DataDictionary();
}
(I'm working on a pull request for that)
In the meantime, the workaround is to include the options with the Properties defined:
private static readonly QueueEntryOptions _dummyOptions = new QueueEntryOptions {Properties = new DataDictionary()};
// :
// :
await _queueClient.EnqueueAsync(message, _dummyOptions);
Great find! I think that is the proper fix and we'll merge in that pr ASAP. I'm guessing this passed our unit tests due to they all use options.
Sorry about that @jamescurran. Thank you for reporting it!
I'm guessing this passed our unit tests due to they all use options.
Well.... See issue #36 If you don't set the connection string, all tests all appear to pass.