Roslyn Analyzers
Ship analyzers to catch common mistakes at compile time.
Analyzer Package
text
Voltimax.Messaging.Analyzers # Ships with Voltimax.Messaging automaticallyRules
| ID | Severity | Description |
|---|---|---|
VM0001 | Error | Handler delegate has no message parameter |
VM0002 | Error | Handler delegate has multiple message parameters |
VM0003 | Warning | Message type is not serializable (no parameterless ctor, not a record) |
VM0005 | Info | Handler doesn't use CancellationToken - consider adding for graceful shutdown |
VM0006 | Warning | AutoComplete = false but handler never calls CompleteAsync |
VM0007 | Error | ReplyContext requested but message has no ReplyTo - use request/reply pattern |
VM0008 | Warning | Duplicate queue/subscription registration |
VM0010 | Warning | Synchronous handler blocks thread - prefer async |
VM0011 | Error | SessionContext requested on non-session queue |
VM0012 | Warning | Message 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
| ID | Fix |
|---|---|
VM0005 | Add CancellationToken ct parameter |
VM0006 | Add await context.CompleteAsync(ct); or enable auto-complete |
VM0010 | Convert to async method |