CHR0050: `[EventType]` and `[EventTypeGenerationFor<T>]` cannot be combined
Rule Description
Section titled “Rule Description”A type is either the current event type (marked with [EventType]) or a previous generation of one (marked with [EventTypeGenerationFor<T>]), never both. Remove one of the two attributes.
Severity
Section titled “Severity”Error
Example
Section titled “Example”Violation
Section titled “Violation”using Cratis.Chronicle.Events;
// Error CHR0050: 'Chr0050ViolationUserRegistered' is marked with both [EventType] and// [EventTypeGenerationFor<T>].[EventType("user-registered")][EventTypeGenerationFor<Chr0050ViolationUserRegisteredV2>(1)]public record Chr0050ViolationUserRegistered(string Name, string Email);
[EventType("user-registered", generation: 2)]public record Chr0050ViolationUserRegisteredV2(string FirstName, string LastName, string Email);using Cratis.Chronicle.Events;
// The previous generation carries only [EventTypeGenerationFor<T>].[EventTypeGenerationFor<Chr0050FixUserRegisteredV2>(1)]public record Chr0050FixUserRegisteredV1(string Name, string Email);
// The current generation carries only [EventType].[EventType("user-registered", generation: 2)]public record Chr0050FixUserRegisteredV2(string FirstName, string LastName, string Email);Why This Rule Exists
Section titled “Why This Rule Exists”[EventType] declares a type as the current representation of an event, giving it an event type id. [EventTypeGenerationFor<T>] declares a type as a previous generation that should be migrated forward into the current shape. Combining them is contradictory: a type cannot simultaneously be the current generation and a previous one.
Without this check, a type marked with both attributes compiles cleanly but fails when the client connects to Chronicle, throwing EventTypeGenerationForCannotBeCombinedWithEventType at startup. This rule surfaces the same mistake at compile time instead.
The same analyzer class also reports CHR0049 (EventTypeGenerationForMustReferenceEventType, Error) when [EventTypeGenerationFor<T>] references a type that itself has no [EventType] attribute — see CHR0049 for that related check.
Related Rules
Section titled “Related Rules”- CHR0049:
[EventTypeGenerationFor<T>]must reference a type marked with[EventType]— validates that the referenced type is actually an event type. - CHR0037: Event type migration generations must belong to one event type — validates that a migration’s two generations resolve to the same event type id.