Skip to content

CHR0034: [PII] cannot be applied to an EventSourceId<T>

A property or record parameter whose type derives from EventSourceId<T> is marked with [PII]. The event source id is used to correlate events, so it cannot itself be encrypted. Applying [PII] to it throws PIINotSupportedOnEventSourceId at runtime.

Remove the [PII] attribute. The event source id is the default compliance subject, but an explicit subject can identify someone else.

Error

using Cratis.Chronicle.Compliance.GDPR;
using Cratis.Chronicle.Events;
// Error CHR0034: 'CustomerId' is typed as 'CustomerId' (derives from EventSourceId<T>);
// [PII] cannot be applied to an event source id — Chronicle throws
// PIINotSupportedOnEventSourceId at runtime. Remove [PII].
[EventType]
public record CustomerRegistered([PII] Chr0034CustomerId CustomerId, string Name);
public record Chr0034CustomerId(Guid Value) : EventSourceId<Guid>(Value)
{
public static implicit operator Chr0034CustomerId(Guid value) => new(value);
}

View C# snippet source on GitHub

Chronicle encrypts [PII] values per subject. The subject defaults to the event source id, but an explicit subject argument or a [Subject] member can supply a different identity. Regardless of the subject, event source identifiers must remain available for event correlation, so Chronicle throws PIINotSupportedOnEventSourceId when [PII] is applied to one.

This analyzer turns that runtime failure into a compile-time error, caught the moment you write the attribute rather than the first time the event is appended.

If the identifier itself is sensitive, do not try to encrypt the id. Instead use a random Guid-backed surrogate as the event source id and store the sensitive value in a separate [PII] property, which Chronicle can encrypt under the resolved subject.