Skip to content

Fix duplicate DisplayName ArgumentException#1072

Draft
robertsmns wants to merge 6 commits intodevfrom
fix/log-duplicate-displaynames
Draft

Fix duplicate DisplayName ArgumentException#1072
robertsmns wants to merge 6 commits intodevfrom
fix/log-duplicate-displaynames

Conversation

@robertsmns
Copy link
Contributor

This PR adds safe handling for duplicate DisplayName values within ToCellPropertySettings to prevent ArgumentException caused by duplicate dictionary keys.

@robertsmns robertsmns self-assigned this Feb 5, 2026
@robertsmns robertsmns added the good first issue Good for newcomers label Feb 5, 2026
};
cellProperties.Add(cellEntry.DisplayName, property);

if (cellProperties.ContainsKey(cellEntry.DisplayName))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding the display name of the property to the CellPropertySettings and using a really unique key like the property name would be more preferable here, then just replacing it and logging a warning 🤔 The display name is never a good dictionary key 🙈
Mind, however, you will have to adjust that on the UI side as well then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the section in the for loop btw. And if the code is identical for creating the cell properties I think a private method makes sense here 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the key handling and property creation

public Converter(ICustomSerialization serialization, IModuleLogger logger = null)
{
Serialization = serialization;
Logger = logger;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an internal component. Why this nullability? Complexity could be reduced here when you don't allow null. The logger can also be a private field instead of a public property.

Comment on lines -47 to +63
if (current == null) return null;

return new ActivityChangedModel
{
ResourceId = current.Id,
};
return current == null
? null
: new ActivityChangedModel
{
ResourceId = current.Id,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer readability in such cases.

if (current == null) 
{
    return null;
}

return new ActivityChangedModel 
{
    ResourceId = current.Id
}

cellProperties.Add(item.Key, item.Value);
if (cellProperties.ContainsKey(item.Key))
{
Logger?.LogWarning($"Duplicate DisplayName '{item.Key}' in resource '{baseType.Name}'. Overwriting previous value. Ensure unique DisplayNames.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Logger.LogWarning("Duplicate DisplayName '{itemKey}' in resource '{baseTypeName}'. Overwriting previous value. Ensure unique DisplayNames.", item.Key, baseType.Name);

@robertsmns robertsmns marked this pull request as draft February 6, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants