Skip to content

JsonSerialisationOptions.Options applies DictionaryKeyPolicy to MessageHeader.Bag, breaking session-keyed delivery #4151

Description

@Jonny-Freemarket

Describe the bug

Paramore.Brighter.JsonConverters.JsonSerialisationOptions.Options sets PropertyNamingPolicy = JsonNamingPolicy.CamelCase. DictionaryStringObjectJsonConverter applies that policy to dictionary keys as well as property names.

As a result, MessageHeader.Bag["SessionId"] is serialised as "sessionId". On the consume side, the ASB publisher does a case-sensitive Bag.TryGetValue("SessionId", out _) to decide whether to set ServiceBusMessage.SessionId. The lookup misses, the message is sent without a session, and the ASB broker silently drops it when the destination subscription has session-required = true.

Bag keys are arbitrary string identifiers, not C# property names — applying a property naming policy to them is semantically wrong, and the failure mode is fully silent (no exception, no log line, the message just never arrives).

To Reproduce

  1. Configure a session-required ASB subscription.
  2. Send a Brighter message whose MessageHeader.Bag["SessionId"] is set.
  3. Round-trip the message through Brighter's STJ serialisation (e.g. via the scheduler envelope path, or any path using JsonSerialisationOptions.Options).
  4. Observe the bag at the publisher: the key is now "sessionId".
  5. Publisher's Bag.TryGetValue("SessionId", ...) misses → session-less message → silent drop.

Suggested fix

Set DictionaryKeyPolicy = null on JsonSerialisationOptions.Options (and any sibling options contributing to the envelope serialiser). Bag keys are user-defined identifiers and must round-trip verbatim.

(Alternative — case-insensitive lookup at fire time — papers over symptoms; the root issue is the bag's keys being mutated by a naming policy.)

Further technical details

  • Brighter version: 10.4.1
  • dotnet --info:
    .NET SDK 10.0.108 (commit 94ea82652c, MSBuild 18.0.11+94ea82652)
    Host 10.0.8 (x64)
    RID: win-x64
    
  • OS: Windows 11 (build 10.0.26200)

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions