Skip to content

[Host.AmazonSQS] NullReferenceException when consuming plain SQS Messages without MessageAttributes #441

Closed

Description

@dboschm

When using SQS With a Plain SQS Setup I get a NullRefercenException when there are no MessageAttributes set on the SQS message.
Unfortunately this is the default for some direct AWS service integrations like e.g. Iot Topic Rules.

I was able to pin this down to this line:
https://github.com/zarusz/SlimMessageBus/blob/81a501af476ba1c820a613c984d87c599acdf016/src/SlimMessageBus.Host.AmazonSQS/Consumer/SqsBaseConsumer.cs#L172C13-L172C27

private void GetPayloadAndHeadersFromMessage(Message message, out string messagePayload, out Dictionary<string, object> messageHeaders)
    {
        if (_isSubscribedToTopic)
        {
        ...
        }
        else
        {
            messagePayload = message.Body;

            messageHeaders = message.MessageAttributes // --> MessageAttributes is a nullable Dictionary according to AWS SDK Client.  
                .ToDictionary(x => x.Key, x => HeaderSerializer.Deserialize(x.Key, x.Value));
        }
    }

Potential fix would be a ?? null check.

Activity

  1. zarusz commented on Nov 12, 2025

    @zarusz
    Owner

    Great catch, @dboschm! We can either use ?? or initialize an empty dictionary (which I prefer). With the major AWS SDK version upgrade, the SDK now sets most collections to null when they’re empty. This behavior slipped through during the upgrade, so thanks for bringing it to our attention.

    Would you like to open a PR with the fix?

  2. zarusz commented on Nov 14, 2025

    @zarusz
    Owner

    Fix released in 3.3.5 via #442

    @dboschm thanks for your contribution!

  3. added this to the 3.3.5 milestone on Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions