Skip to content

CHR0007: Reducer event parameter must have [EventType] attribute

Event parameters in reducer methods must be types marked with the [EventType] attribute. This ensures that reducers only handle properly identified event types.

Error

using Cratis.Chronicle.Reducers;
// Missing [EventType] attribute
public record Chr0007InventoryAdjusted(string ProductId, int Quantity);
public class Chr0007InventoryState
{
public int Quantity { get; set; }
}
public class Chr0007InventoryReducer : IReducerFor<Chr0007InventoryState>
{
// CHR0007: Type 'Chr0007InventoryAdjusted' must be marked with [EventType] attribute
public void Adjusted(Chr0007InventoryAdjusted @event)
{
}
}
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Reducers;
[EventType]
public record Chr0007InventoryAdjustedFixed(string ProductId, int Quantity);
public class Chr0007InventoryStateFixed
{
public int Quantity { get; set; }
}
public class Chr0007InventoryReducerFixed : IReducerFor<Chr0007InventoryStateFixed>
{
// Now valid
public void Adjusted(Chr0007InventoryAdjustedFixed @event)
{
}
}

The analyzer provides a code fix that automatically adds the [EventType] attribute to the event parameter type.

Reducers build state from events in a deterministic way. Ensuring all event types are properly marked:

  • Guarantees proper event routing to reducers
  • Enables type-safe state reduction
  • Ensures events are correctly serialized/deserialized
  • Maintains schema tracking for events
  • Allows for proper reducer replay and catchup
  • CHR0001: Event sequence append operations
  • CHR0005: Reactor event parameters
  • CHR0006: Reducer method signatures