Skip to main content

FDDB0021: DynamicFields property already exists

FieldValue
CodeFDDB0021
SeverityWarning

Message

Class '{0}' is marked with [EnableDynamicFields] but already has a DynamicFields property. The generated property will conflict with the existing one.

Description

When using [EnableDynamicFields], the source generator adds a DynamicFields property. If the class already has this property, there will be a conflict.

Remove the manually defined DynamicFields property and let the source generator create it, or remove the [EnableDynamicFields] attribute if you prefer to manage dynamic fields manually.

Example

The following code triggers this diagnostic:

[DynamoDbTable("nodes")]
[EnableDynamicFields]
public partial class TreeNode
{
[PartitionKey]
[DynamoDbAttribute("pk")]
public string Pk { get; set; } = string.Empty;

[SortKey]
[DynamoDbAttribute("sk")]
public string Sk { get; set; } = string.Empty;

// Conflicts with the generated property
public DynamicFieldCollection DynamicFields { get; set; } = new();
}

Fix

The corrected version:

[DynamoDbTable("nodes")]
[EnableDynamicFields]
public partial class TreeNode
{
[PartitionKey]
[DynamoDbAttribute("pk")]
public string Pk { get; set; } = string.Empty;

[SortKey]
[DynamoDbAttribute("sk")]
public string Sk { get; set; } = string.Empty;

// DynamicFields property is auto-generated
}