LiteBus
Reference

Analyzers

LiteBus.Analyzers ships Roslyn rules that catch handler registration mistakes, durable contract gaps, and inbox misuse at compile time. Reference the package from application and test projects that use LiteBus mediators or durable writers.

<PackageReference Include="LiteBus.Analyzers" PrivateAssets="all" />

Analyzers have no runtime dependency on LiteBus libraries.

Rule Inventory (LB1001-LB1017)

IDSeverityCategorySummary
LB1001ErrorHandlersDuplicate ICommandHandler<TCommand> for the same command type
LB1002ReservedHandlersNot implemented. Event multicast is supported, so duplicate event handlers are not reported by this rule.
LB1003WarningHandlersQuery or stream query handler depends on command, event, inbox, or outbox APIs
LB1004ErrorInboxICommand<TResult> passed to IInbox.AcceptAsync, AcceptBatchAsync, or ITransactionalInbox.AcceptAsync
LB1005ErrorHandlersOpen generic handler exposes unsupported generic arity
LB1007WarningContractsHandled durable command/event lacks [MessageContract] and explicit Contracts.Register / RegisterFromAssembly
LB1008ErrorHandlersCommand type has no main command handler in the compilation
LB1009ErrorHandlersQuery or stream query type has no main handler in the compilation
LB1010ErrorHandlersDuplicate IQueryHandler<TQuery, TResult> or IStreamQueryHandler<TQuery, TResult> for the same query type
LB1011WarningHandlers[HandlerTag] is not referenced by command, query, or event mediation tag filters
LB1012WarningHandlersSame handler simple name appears in multiple assemblies (risk of double RegisterFromAssembly)
LB1013WarningOutboxConstructor injects ITransactionalOutboxStore without a DbContext in the same constructor
LB1014ErrorConfigurationInbox or outbox processor enabled without a dispatcher in the same module builder scope
LB1015WarningConfigurationTransactional EF storage calls EnforceTransactionalSetup() without EnableSaveChangesInterceptor()
LB1016WarningInboxConstructor injects ITransactionalInboxStore without a DbContext in the same constructor
LB1017WarningContractsType declares [MessageContract] but lacks explicit Contracts.Register or RegisterFromAssembly in the compilation

Contract Registration Split (LB1007 vs LB1017)

  • LB1007 fires on handled durable types that have neither [MessageContract] nor registration discovered through Contracts.Register<T>() or RegisterFromAssembly.
  • LB1017 fires on attributed durable types that lack explicit registration. Runtime on-demand resolution still works; explicit registration is recommended for predictable discovery.

Both rules treat RegisterFromAssembly / AddFromAssembly as satisfying explicit registration. LB1017 matches only IContractWriter / IMessageContractRegistry Register invocations, not unrelated Register<T>() methods.

Inbox Result Commands (LB1004)

The inbox replays stored commands later and discards handler results. Only result-less ICommand types may be accepted. LB1004 covers AcceptAsync, AcceptBatchAsync (including InboxAcceptItem.From in array and collection-expression batches), and transactional inbox acceptance APIs.

Query and Stream Query Handlers (LB1009 and LB1010)

LB1009 reports query types without IQueryHandler<TQuery, TResult> and stream query types without IStreamQueryHandler<TQuery, TResult>. Stream queries implementing IStreamQuery<TResult> are not checked against query handlers. LB1010 applies the same duplicate detection to both handler kinds. Message type discovery for LB1008, LB1009, and LB1010, and handler registration scanning, include eligible referenced assemblies (same filter as handler registration scanning).

Reserved Event Handler Slot (LB1002)

LB1002 is intentionally unused in the shipped analyzer set. Event mediation supports multiple handlers for one event type, so the command and query duplicate rules do not have an event equivalent. LB1012 still warns when the same handler simple name appears in multiple assemblies.

Suppression

Use #pragma warning disable LB1007 (or the relevant ID) sparingly. Prefer fixing registration or handler shape.

See Also

On this page