rebus-org / Rebus.AzureServiceBus

:bus: Azure Service Bus transport for Rebus
https://mookid.dk/category/rebus
Other
33 stars 20 forks source link

Receive message : Error when a user property has value = null #52

Closed sabbadino closed 4 years ago

sabbadino commented 4 years ago

Using Rebus service bus 7.1.0

I think this line of code has a problem var headers = userProperties.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToString());

if kvp.Valueis null it breaks with :

Exception thrown: 'System.NullReferenceException' in System.Private.CoreLib.dll dmbo.v3.partner.api Warning: 0 : 2020-03-17 09:39:06.085 +01:00 [Warning] An error occurred when attempting to receive the next message: "System.NullReferenceException: Object reference not set to an instance of an object. at Rebus.AzureServiceBus.AzureServiceBusTransport.<>c.b__36_4(KeyValuePair2 kvp) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer`1 comparer) at Rebus.AzureServiceBus.AzureServiceBusTransport.Receive(ITransactionContext context, CancellationToken cancellationToken) at Rebus.Workers.ThreadPoolBased.ThreadPoolWorker.ReceiveTransportMessage(CancellationToken token, ITransactionContext context) in C:\projects-rebus\Rebus\Rebus\Workers\ThreadPoolBased\ThreadPoolWorker.cs:line 148"

I would even check if userProperties is not null

mookid8000 commented 4 years ago

When is the UserProperties property of the incoming message null?

sabbadino commented 4 years ago

I don't know if the userproperty can ever be null .. it's an asb sdk read only prop ..

For sure the rebus code fails if someone put a custom header whose value is null (which is legal even if unusual.. and this was my situation)

mookid8000 commented 4 years ago

ah, damn... that should definitely be fixed 🙂

mookid8000 commented 4 years ago

fixed in Rebus.AzureServiceBus 7.1.1, which is out on NuGet.org now 🙂 thanks for reporting this issue!