Skip to content

Commit 3e49afb

Browse files
committed
Fixed Argument Null Exception with unresolved mapping and added logging
1 parent 97159f0 commit 3e49afb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Foundatio/Messaging/MessageBusBase.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ protected virtual bool SubscriberHandlesMessage(Subscriber subscriber, IMessage
141141
return true;
142142

143143
var clrType = message.ClrType ?? GetMappedMessageType(message.Type);
144+
if (clrType is null) {
145+
if (_logger.IsEnabled(LogLevel.Warning))
146+
_logger.LogWarning("Unable to resolve CLR type for message body type: ClrType={MessageClrType} Type={MessageType}", message.ClrType, message.Type);
147+
148+
return false;
149+
}
150+
144151
if (subscriber.IsAssignableFrom(clrType))
145152
return true;
146153

@@ -340,6 +347,9 @@ protected class Subscriber {
340347
public Func<object, CancellationToken, Task> Action { get; set; }
341348

342349
public bool IsAssignableFrom(Type type) {
350+
if (type is null)
351+
return false;
352+
343353
return _assignableTypesCache.GetOrAdd(type, t => {
344354
if (t.IsClass) {
345355
var typedMessageType = typeof(IMessage<>).MakeGenericType(t);

0 commit comments

Comments
 (0)