---
title: 'CHR0052: [Encrypted] cannot be applied to an EventSourceId&lt;T&gt;'
editUrl: https://github.com/Cratis/Chronicle/edit/main/Documentation/code-analysis/CHR0052.mdx
---

import { Tabs, TabItem } from '@astrojs/starlight/components';

## Rule Description

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

Remove the `[Encrypted]` attribute.

## Severity

Error

## Example

### Violation

<Tabs syncKey="chronicle-client">
<TabItem label="C#">

```csharp
public record Chr0052PartnerId(Guid Value) : EventSourceId<Guid>(Value);

public record Chr0052PartnerIntegrationConfigured(
    [Encrypted] Chr0052PartnerId PartnerId,
    string ApiKey);
```

[View C# snippet source on GitHub](https://github.com/Cratis/Chronicle/blob/main/Documentation/client-snippets/code-analysis/chr0052/violation.md)

</TabItem>
</Tabs>

### Fix

<Tabs syncKey="chronicle-client">
<TabItem label="C#">

```csharp
public record Chr0052PartnerIdFixed(Guid Value) : EventSourceId<Guid>(Value);

public record Chr0052PartnerIntegrationConfiguredFixed(
    Chr0052PartnerIdFixed PartnerId,
    [Encrypted] string ApiKey);
```

[View C# snippet source on GitHub](https://github.com/Cratis/Chronicle/blob/main/Documentation/client-snippets/code-analysis/chr0052/fix.md)

</TabItem>
</Tabs>

## Why This Rule Exists

This rule mirrors [CHR0034](/chronicle/code-analysis/chr0034/) for `[Encrypted]` values. If the identifier itself is a secret, do not try to encrypt the id — use a non-sensitive surrogate as the event source id and store the secret in a separate `[Encrypted]` property.

## Related Rules

- [CHR0034](/chronicle/code-analysis/chr0034/): `[PII]` cannot be applied to an `EventSourceId<T>` — the same restriction for compliance values.
- [CHR0053](/chronicle/code-analysis/chr0053/): `[PII]` and `[Encrypted]` cannot both apply to the same value.
