Skip to content

CHR0001: Event type must have [EventType] attribute

Types that are appended to event sequences must be marked with the [EventType] attribute. This ensures that all events in the event store are properly identified and can be correctly deserialized.

Error

using Cratis.Chronicle.Events;
using Cratis.Chronicle.EventSequences;
// Missing [EventType] attribute
public record Chr0001UserCreated(string Username, string Email);
public class Chr0001UserService(IEventSequence eventSequence)
{
public Task CreateUser(EventSourceId userId, string username, string email) =>
// CHR0001: Type 'Chr0001UserCreated' must be marked with [EventType] attribute
eventSequence.Append(userId, new Chr0001UserCreated(username, email));
}
using Cratis.Chronicle.Events;
using Cratis.Chronicle.EventSequences;
[EventType]
public record Chr0001UserCreatedFixed(string Username, string Email);
public class Chr0001UserServiceFixed(IEventSequence eventSequence)
{
public Task CreateUser(EventSourceId userId, string username, string email) =>
// Now valid
eventSequence.Append(userId, new Chr0001UserCreatedFixed(username, email));
}

The analyzer provides a code fix that automatically:

  1. Adds the [EventType] attribute to the event type
  2. Adds the required using directive if not already present

The [EventType] attribute is crucial for Chronicle’s event handling:

  • It uniquely identifies the event type in the event store
  • It enables proper event serialization and deserialization
  • It allows Chronicle to track event type generations and schemas
  • It ensures type safety when working with events
  • CHR0003: Model bound projection attributes
  • CHR0005: Reactor event parameters
  • CHR0007: Reducer event parameters