Skip to content

SqlServiceBrokerOptionsBuilder: WithConnectionString before AddSqlServiceBrokerOptions throws NullReferenceException; compression cannot be disabled fluently #532

Description

@brenpike

Summary

Two usability defects in SqlServiceBrokerOptionsBuilder (src/Chatter.MessageBrokers.SqlServiceBroker/src/Chatter.MessageBrokers.SqlServiceBroker/Configuration/SqlServiceBrokerOptionsBuilder.cs). Found while rewriting the module README (branch docs/readme-overhaul); the README tells readers to call an AddSqlServiceBrokerOptions overload first.

1. With* methods throw NullReferenceException before an AddSqlServiceBrokerOptions overload

_sqlServiceBrokerOptions is only assigned inside the AddSqlServiceBrokerOptions overloads (:19, :25, :38). WithConnectionString (:53-57) and the other With* setters dereference it directly, so calling them first throws NullReferenceException. Meanwhile the Build() error message (:144-149) says "Use an overload of AddSqlServiceBrokerOptions or WithConnectionString to configure SqlServiceBrokerOptions", which suggests WithConnectionString alone is enough.

Fix options: initialise a default options instance so WithConnectionString works on its own, or throw a clear InvalidOperationException and correct the Build() message.

2. Compression cannot be turned off through the fluent API

WithMessageBodyCompression() (:117-121) sets CompressMessageBody = true, which is already the default. There is no fluent way to disable compression; you have to pass compressMessageBody: false to an AddSqlServiceBrokerOptions overload. Consider WithMessageBodyCompression(bool enabled = true) or a WithoutMessageBodyCompression() counterpart.

Impact

Low: developer-experience traps, no runtime data impact.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdifficulty:lowtriage difficulty ratingeffort:xstriage effort ratingmoscow:couldtriage moscow ratingpriority:lowtriage priority ratingreadiness:readytriage readiness ratingrisk:lowtriage risk ratingtype:bugtriage type rating

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions