Skip to content

Roslyn Analyzers

Ship analyzers to catch common mistakes at compile time.

Analyzer Package

text
Voltimax.Messaging.Analyzers    # Ships with Voltimax.Messaging automatically

Rules

IDSeverityDescription
VM0001ErrorHandler delegate has no message parameter
VM0002ErrorHandler delegate has multiple message parameters
VM0003WarningMessage type is not serializable (no parameterless ctor, not a record)
VM0005InfoHandler doesn't use CancellationToken - consider adding for graceful shutdown
VM0006WarningAutoComplete = false but handler never calls CompleteAsync
VM0007ErrorReplyContext requested but message has no ReplyTo - use request/reply pattern
VM0008WarningDuplicate queue/subscription registration
VM0010WarningSynchronous handler blocks thread - prefer async
VM0011ErrorSessionContext requested on non-session queue
VM0012WarningMessage type has no properties - likely a mistake

Example Diagnostics

csharp
// VM0001: Handler delegate has no message parameter
messaging.MapQueue<OrderCreated>("orders").MapHandler(() => { }); // ❌

// VM0003: Message type is not serializable
public class BadMessage { public BadMessage(int x) { } } // ❌ No parameterless ctor

// VM0005: Consider adding CancellationToken
messaging.MapQueue<OrderCreated>("orders").MapHandler((OrderCreated msg) => { }); // ⚠️

// VM0006: AutoComplete disabled but no settlement
messaging.MapQueue<OrderCreated>("orders")
    .MapHandler(opts => opts.WithAutoComplete(false), (OrderCreated msg) => { }); // ⚠️ Message will never complete

// VM0008: Duplicate handler registration
messaging.MapQueue<OrderCreated>("orders").MapHandler(handler1);
messaging.MapQueue<OrderCreated>("orders").MapHandler(handler2); // ⚠️

Code Fixes

IDFix
VM0005Add CancellationToken ct parameter
VM0006Add await context.CompleteAsync(ct); or enable auto-complete
VM0010Convert to async method