Foundatio.AzureServiceBus icon indicating copy to clipboard operation
Foundatio.AzureServiceBus copied to clipboard

NullReference Exception on Enqueuing

Open jamescurran opened this issue 3 years ago • 3 comments

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);

jamescurran avatar Oct 22 '20 02:10 jamescurran

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.

niemyjski avatar Oct 22 '20 12:10 niemyjski

Sorry about that @jamescurran. Thank you for reporting it!

ejsmith avatar Oct 22 '20 15:10 ejsmith

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.

jamescurran avatar Oct 23 '20 07:10 jamescurran