From 0e7ce0a93e4b3c4a9361b8a7c6f6c262002f4625 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sun, 25 Nov 2018 10:23:08 +0000 Subject: [PATCH 1/3] Fix NullReferenceException Fix NullReferenceException when configuring publishing and subscribing if no IMessageSerialisationFactory is configured. --- JustSaying/JustSayingFluently.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/JustSaying/JustSayingFluently.cs b/JustSaying/JustSayingFluently.cs index d822627d6..2cc5d6284 100644 --- a/JustSaying/JustSayingFluently.cs +++ b/JustSaying/JustSayingFluently.cs @@ -6,11 +6,11 @@ using JustSaying.AwsTools.MessageHandling; using JustSaying.AwsTools.QueueCreation; using JustSaying.Extensions; +using JustSaying.Messaging.Interrogation; using JustSaying.Messaging.MessageHandling; using JustSaying.Messaging.MessageSerialisation; using JustSaying.Messaging.Monitoring; using JustSaying.Models; -using JustSaying.Messaging.Interrogation; using Microsoft.Extensions.Logging; namespace JustSaying @@ -232,6 +232,11 @@ public IFluentSubscription IntoQueue(string queuename) /// public IHaveFulfilledSubscriptionRequirements WithMessageHandler(IHandlerAsync handler) where T : Message { + if (_serialisationFactory == null) + { + throw new InvalidOperationException($"No {nameof(IMessageSerialisationFactory)} has been configured."); + } + // TODO - Subscription listeners should be just added once per queue, // and not for each message handler var thing = _subscriptionConfig.SubscriptionType == SubscriptionType.PointToPoint @@ -250,6 +255,11 @@ public IHaveFulfilledSubscriptionRequirements WithMessageHandler(IHandlerAsyn public IHaveFulfilledSubscriptionRequirements WithMessageHandler(IHandlerResolver handlerResolver) where T : Message { + if (_serialisationFactory == null) + { + throw new InvalidOperationException($"No {nameof(IMessageSerialisationFactory)} has been configured."); + } + var thing = _subscriptionConfig.SubscriptionType == SubscriptionType.PointToPoint ? PointToPointHandler() : TopicHandler(); From fbb219a3037257d80c98f147df473f1ffb75c938 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sun, 25 Nov 2018 17:25:57 +0000 Subject: [PATCH 2/3] Add null check for handlers Add null check on handlers. Specify argument name in exception. --- JustSaying/JustSayingFluentlyExtensions.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/JustSaying/JustSayingFluentlyExtensions.cs b/JustSaying/JustSayingFluentlyExtensions.cs index 25bf79fd4..5c9d69652 100644 --- a/JustSaying/JustSayingFluentlyExtensions.cs +++ b/JustSaying/JustSayingFluentlyExtensions.cs @@ -66,9 +66,14 @@ public static IFluentSubscription IntoDefaultQueue(this ISubscriberIntoQueue sub public static IHaveFulfilledSubscriptionRequirements WithMessageHandlers( this IFluentSubscription sub, params IHandlerAsync[] handlers) where T : Message { + if (handlers == null) + { + throw new ArgumentNullException(nameof(handlers)); + } + if (handlers.Length == 0) { - throw new ArgumentException("No handlers in list"); + throw new ArgumentException("No message handlers specified.", nameof(handlers)); } if (handlers.Length == 1) From db14511a177aa03222e523d8c903b9a637bea866 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sun, 25 Nov 2018 17:30:44 +0000 Subject: [PATCH 3/3] Add null check for handler Add a null check on handler. --- JustSaying/JustSayingFluently.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/JustSaying/JustSayingFluently.cs b/JustSaying/JustSayingFluently.cs index 2cc5d6284..c4519e3be 100644 --- a/JustSaying/JustSayingFluently.cs +++ b/JustSaying/JustSayingFluently.cs @@ -232,6 +232,11 @@ public IFluentSubscription IntoQueue(string queuename) /// public IHaveFulfilledSubscriptionRequirements WithMessageHandler(IHandlerAsync handler) where T : Message { + if (handler == null) + { + throw new ArgumentNullException(nameof(handler)); + } + if (_serialisationFactory == null) { throw new InvalidOperationException($"No {nameof(IMessageSerialisationFactory)} has been configured.");