Skip to content

Cratis Chronicle analyzer rule reference

Cratis Chronicle’s .NET analyzers check C# code for Chronicle usage mistakes during compilation. Each finding has a CHR#### diagnostic ID that identifies the rule behind the build or editor message.

To resolve a diagnostic, find its ID in the rules overview and open the linked rule page for the cause and correction. If you’re adding the analyzers or upgrading the client, start with installation. The quick fixes section lists automated corrections.

Rule IDs are not a continuous sequence. The table includes the retired CHR0047 rule so you can still look up an older diagnostic or suppression.

Rule ID Title Severity Description
CHR0001 Event type must have [EventType] attribute Error Appended event types need [EventType], [EventTypeGenerationFor<T>], or explicit registration
CHR0002 Declarative projection event type must have [EventType] attribute Error Declarative projection generic arguments must reference attributed or explicitly registered event types
CHR0003 Model bound projection attribute must reference event type with [EventType] attribute Error Model-bound projection attributes must reference attributed or explicitly registered event types
CHR0004 Reactor method has a parameter that cannot be resolved Warning Reactor method dependencies must be resolvable from event context, read models, or services
CHR0005 Reactor event parameter must have [EventType] attribute Error Reactor event parameters must be recognized as event types through attributes or explicit registration
CHR0006 Reducer method signature must match allowed signatures Warning Reducer methods must follow allowed signatures
CHR0007 Reducer event parameter must have [EventType] attribute Error Reducer event parameters must be recognized as event types through attributes or explicit registration
CHR0008 Reactor event types must be from the same event store Error Reactor event types must all originate from the same event store
CHR0009 Reducer event types must be from the same event store Error Reducer event types must all originate from the same event store
CHR0010 Model-bound projection event types must be from the same event store Error Model-bound projection event types must all originate from the same event store
CHR0011 Declarative projection event types must be from the same event store Error Declarative projection event types must all originate from the same event store
CHR0012 Event types should avoid nullable properties Warning Nullable properties are supported on events but are often better modeled as separate event types
CHR0013 Reactor cannot combine EventStore with explicit event sequence Error Reactors with [EventStore] must not also configure an explicit event sequence
CHR0014 Reducer cannot combine EventStore with explicit event sequence Error Reducers with [EventStore] must not also configure an explicit event sequence
CHR0015 Projection must not have side effects Error Projections must not inject ICommandPipeline or IEventLog
CHR0016 Projection Define() must not contain imperative code Error Projection Define() must only contain builder calls, not imperative statements
CHR0017 Constraint must not have side effects Error Constraints must not inject ICommandPipeline or IEventLog
CHR0018 Constraint Define() must not contain imperative code Error Constraint Define() must only contain builder calls, not imperative statements
CHR0019 Projection expression lambda must only access members Error Expression lambdas in projection builder methods must be simple member-access expressions
CHR0020 Constraint expression lambda must only access members Error Expression lambdas in constraint builder methods must be simple member-access expressions
CHR0021 Event types should be record types Warning Event types should be declared as record types for immutability
CHR0022 Reactor methods returning event side effects must be marked with [OnceOnly] Warning Reactor methods that return events must be [OnceOnly] to avoid appending duplicates during replay
CHR0023 Ambiguous parent key for [ChildrenFrom] collection Warning Parent-key inference is ambiguous when the child event has more than one property of the parent identifier type; specify parentKey
CHR0024 Read model property has no mapping source Warning A model-bound read model property has no mapping attribute and no subscribed event carries a same-named property, so AutoMap can never populate it
CHR0025 Explicitly sourced read model property may be overwritten by AutoMap Info A property set with [SetFrom]/[SetValue]/… collides by name with another referenced event that AutoMap writes on top; add [NoAutoMap] or accept the update
CHR0026 [Key] on an EventSourceId<T> is redundant Warning An EventSourceId<T>-derived property already carries the key role; remove [Key] while preserving any explicit [Subject]
CHR0027 Ambiguous event stream id Error A type both implements ICanProvideEventStreamId and declares a non-null [EventStreamId]; this throws at startup
CHR0028 Redundant .AutoMap() call Warning .AutoMap() has no effect because AutoMap is enabled by default on projection builders; remove the call
CHR0029 Redundant .Set().To() with matching property names Warning A .Set(x => x.P).To(e => e.P) mapping with identical names duplicates what AutoMap already does; remove it
CHR0030 [ChildrenFrom] child collection property auto-maps to nothing Warning A [ChildrenFrom] child collection property matching no event property and with no explicit mapping always projects empty; rename it or bridge with [SetFrom<T>]
CHR0031 Reactor must not have mutable state Warning Reactors are re-created and replayed, so mutable instance state is unreliable; use readonly, primary-constructor-injected dependencies
CHR0032 Reactor must not access storage directly Warning Injecting a storage primitive like IMongoCollection<T> couples the reactor to a sink; read state via a read model or IReadModels.GetInstanceById
CHR0034 [PII] cannot be applied to an EventSourceId<T> Error The event source id is the encryption-key lookup identity, so it cannot be encrypted; [PII] on it throws PIINotSupportedOnEventSourceId at runtime
CHR0035 Read model declares a reserved compliance subject property Error Chronicle reserves _subject, __subject, and __subjects for internal compliance-subject tracking; a same-named property collides with stored metadata
CHR0036 Reducer must not have mutable state Warning Reducers are re-created and replayed, so mutable instance state or direct storage injection makes the fold non-deterministic; keep them stateless
CHR0037 Event type migration generations must belong to one event type Warning The two generations referenced by an EventTypeMigration must resolve to the same event type id and differ only by generation, or the migration never applies — checked for both EventTypeGenerationFor<T> and the older explicit-id [EventType] style
CHR0039 Assertion result is discarded and can never fail Error An awaitable-returning Should* assertion on a Cratis testing surface whose result is discarded throws on an awaitable nobody observes, so the assertion silently passes regardless of behavior and CS4014 does not fire outside an async method
CHR0040 Several [SetFromContext] for the same event type on one member Warning They write the same property in the definition, so only the last declared is kept and the earlier capture is silently dropped; capturing from several different event types is the supported use and is not flagged
CHR0041 Event filter attribute on a projection has no effect Warning A projection observes every event of the types it declares and cannot filter on event metadata — only reactors and reducers can — so [EventStreamType], [EventSourceType], and [FilterEventsByTag] on a projection are silently ignored
CHR0042 A joined property is also written locally Warning A property written by both a local mapping and a join — model-bound or fluent — always ends up with the joined value regardless of arrival order, so a local write can never reset it; a flag latched from both sides silently sticks
CHR0043 Key redirection carries a [PII] value across the compliance subject Warning A root key or child parent-key redirect carries PII onto a document whose resolved compliance subject is not provably the value owner’s
CHR0045 Event stream metadata attribute on an event type has no effect Warning An append resolves its event source type and event stream type from the append itself, never from the event’s CLR type, so [EventStreamType] and [EventSourceType] on an [EventType] are read by nothing — declare them on the appending command, the observing reactor/reducer, or (for [EventStreamType]) the aggregate root whose appends they identify
CHR0046 Passive read model redirects the document key away from the event’s own stream Warning A passive read model has no sink, so a read replays one event stream constrained to the requested key; a root key redirection points that replay at a stream the events were never appended to and the read returns a default-initialized model
CHR0047 A clear declaration is never applied by projection construction Retired Both declarations it reported - a null [SetValue] and a member-level [ClearWith] - are a working scalar clear now, so the rule was removed; the id stays reserved and is never reused
CHR0048 A clear is declared for a member that cannot hold null Warning Clearing means returning a member to no value; a non-nullable member has no such state, so the only thing the projection could write is the type default - a different fact the read model cannot tell apart from a real value
CHR0049 EventTypeGenerationFor<T> must reference a type marked with [EventType] Error A type marked with EventTypeGenerationFor<T> references a type that is not itself marked with [EventType], so there is no id to resolve the previous generation’s identity from
CHR0050 [EventType] and [EventTypeGenerationFor<T>] cannot be combined Error A type is either the current event type or a previous generation, never both
CHR0051 Reducer current read model parameter must be nullable Warning Chronicle passes null as the current read model for the event that brings an instance into existence
CHR0052 [Encrypted] cannot be applied to an EventSourceId<T> Error The event source id is used to correlate events and cannot be encrypted
CHR0053 [PII] and [Encrypted] cannot both apply to the same value Error Combining them encrypts the value twice, under two different keys, and it cannot be released correctly
CHR0054 Reactor method has an unsupported return type Warning A reactor method with an event parameter must return a shape Chronicle discovers as a handler
CHR0055 Unknown event stream on typed event-source filter Error [FromEventSource<TSource>("stream")] must name a stream the event source definition declares
CHR0056 Explicit routing contradicts typed event-source filter Error [EventSourceType] or [EventStreamType] on the same type may only repeat what [FromEventSource<TSource>] already says
CHR0057 An artifact must target one read model Warning A class implementing multiple closed projection or reducer interfaces fails during default artifact discovery; split it into one artifact per read model
CHR0058 Self reducer method signature must match allowed signatures Warning A Reduce method on a self-reducing read model must be public static with the event, the nullable current model and an optional EventContext
CHR0059 Self reducer lifecycle hook signature must match allowed signatures Error Replay hooks must be unique public static Task methods with only the allowed parameters
CHR0060 Self reducer method must be unambiguous Error A self-reducing read model must not declare several Reduce handlers for the same event type
CHR0061 Read model builder ownership must be unambiguous Warning A self-reducing read model must not be built by another type (Error when it is also a reactor, has a projection mapping or targets itself)
CHR0062 Concurrency applies across event sources Info A Concurrency declaration on a definition or stream that omits EventSourceId is a cross-source condition, not a guard for the state a command read
CHR0063 Scope stream does not match append Warning A definition-linked scope guards a different stream than the single-route append it is passed to
CHR0064 Invalid read model event stream Error A per-stream read model must name one declared stream, keep the event source ID as its key, and cannot be reducer-backed
CHR0065 Read model fold method will not be discovered Warning An event fold on a read model has the wrong name or is not static, so it cannot be discovered as a self reducer
CHR0066 A node or an edge can only have primitive properties Error A property of a node or an edge in a graph projection that is an object
CHR0067 A node needs exactly one key Error A node without exactly one key, or an edge with more than one key
CHR0068 A node or an edge cannot be a read model Error A type that is both a node or an edge in a graph and a read model
CHR0069 [Sink] cannot be combined with [Passive] Error A read model marked both [Sink] and [Passive]
CHR0070 [Observes<T>] is only for batch methods Error [Observes<T>] is on a method that does not take an EventBatch first
CHR0071 Batch method observes no event types Error A method taking an EventBatch declares no [Observes<T>], so it would never be called
CHR0072 An event type reaches more than one method Error An event type is observed by two batch methods of a reactor, or by a batch method and a per-event method
CHR0073 BatchContext is only for batch methods Error A per-event reactor or reducer method takes a BatchContext
CHR0074 Reactor batch method must return Task or void Error Returning events or other side effects from a reactor batch method is not supported
CHR0075 A reducer with a batch method has no other reduce methods Error A reducer has two batch methods, or a batch method and per-event reduce methods
CHR0076 Batch method has a signature Chronicle cannot call Error A batch method’s parameters or result are not ones Chronicle can supply or read
CHR0077 Batch method matches an event type it does not observe Warning A pattern in a batch method names an event type outside its [Observes<T>] list, so it never matches
CHR0078 A graph view must be anchored at a node Error The type given to ViewOf<TNode> is not a node
CHR0079 A relation of a graph view must follow an edge Error The type given to Follows<TEdge> is not an edge
CHR0080 A relation of a graph view must lead to a view Error A relation member’s type, or the item type of its collection, is not a view
CHR0081 A graph view cannot be a node or an edge Error A type is both a view and a node or an edge
CHR0082 Scenario terminal task is discarded Warning A known scenario setup or delivery task is discarded rather than observed
CHR0083 Reactor handler must not be async void Warning An eligible instance reactor handler is async void, so Chronicle cannot await its work
CHR0084 Event type generation is missing a migrator Error An event type at generation 2 or higher lacks an EventTypeMigration<TUpgrade, TPrevious> for one or more steps 1->2 .. (N-1)->N; the message lists the missing steps and what to add

If you register event types explicitly instead of adding [EventType], CHR0001, CHR0002, CHR0003, CHR0005 and CHR0007 can recognize that registration. They inspect ExplicitArtifacts.RegisterEventType<T>() and RegisterEventType(typeof(T), ...) calls across all source files in the same compilation, checking that C# resolves each call to the actual registration method. The diagnostic IDs, severities and messages stay the same. Reactor return types and event sequences also use this evidence. Explicit RegisterReactor and RegisterReducer calls bring observers without markers into the method-signature checks.

Finding a registration call does not prove that it runs or registers the type on the client that uses it. Dead or conditional calls still count. The analyzers recognize closed generic type arguments and literal typeof arguments, but do not evaluate a variable containing a Type. They cannot establish registrations hidden in a referenced library, reflection, a plugin, configuration or an open-generic wrapper.

Registration callbacks, supplied IDs, generations, store ownership and control flow are not interpreted. Other analyzer families still rely on attributes or marker interfaces; explicit registration does not make every rule aware of explicit metadata. Plain migration method roles and endpoint relationships are validated at runtime, not by the migration-ID analyzer.

Validate the actual store configuration at runtime. If registration is correct but invisible to these analyzers, suppress only the relevant CHR0001/2/3/5/7 diagnostic at that use site rather than disabling the analyzers globally. Follow explicit artifact registration to configure registration and understand when the client takes its registration snapshot.

These rules offer code fixes:

  • CHR0001, CHR0002, CHR0003, CHR0005, and CHR0007 add the missing [EventType] attribute to the referenced type.
  • CHR0026 removes the redundant [Key] attribute and preserves [Subject].
  • CHR0028 removes the redundant .AutoMap() call.
  • CHR0029 removes the redundant .Set(...).To(...) mapping.
  • CHR0062 adds EventSourceId to the concurrency dimensions. Use this fix when the condition should apply to one event source rather than across sources.
  • CHR0083 changes an async-void reactor handler’s return type to global::System.Threading.Tasks.Task, preserving its body. Fix All is supported. Overrides and interface implementations are excluded to preserve their signature contracts.

The analyzers ship in the Cratis.Chronicle.CodeAnalysis package. In 19.4.8 and later, Cratis.Chronicle depends on it, so referencing Cratis.Chronicle or a package that depends on it, such as Cratis.Chronicle.AspNetCore, brings the rules into your build without a separate analyzer reference. This package analyzes C# code, not code written for Chronicle’s other clients.

Before 19.4.8, Cratis.Chronicle did not carry the analyzer dependency. Projects on those versions only run the rules if they reference the analyzer package directly. If you’re using an older client, add the package at the same version as the client:

Terminal window
dotnet add package Cratis.Chronicle.CodeAnalysis --version <your Cratis.Chronicle version>