Skip to content

Commit

Permalink
Fixed Argument Null Exception with unresolved mapping and added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Jan 4, 2023
1 parent 97159f0 commit 3e49afb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Foundatio/Messaging/MessageBusBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ protected virtual bool SubscriberHandlesMessage(Subscriber subscriber, IMessage
return true;

var clrType = message.ClrType ?? GetMappedMessageType(message.Type);
if (clrType is null) {
if (_logger.IsEnabled(LogLevel.Warning))
_logger.LogWarning("Unable to resolve CLR type for message body type: ClrType={MessageClrType} Type={MessageType}", message.ClrType, message.Type);

return false;
}

if (subscriber.IsAssignableFrom(clrType))
return true;

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

public bool IsAssignableFrom(Type type) {
if (type is null)
return false;

return _assignableTypesCache.GetOrAdd(type, t => {
if (t.IsClass) {
var typedMessageType = typeof(IMessage<>).MakeGenericType(t);
Expand Down

0 comments on commit 3e49afb

Please sign in to comment.