-
Notifications
You must be signed in to change notification settings - Fork 1k
Add do...while loop in the SetValue method of SerializationResourceManager.cs until resourceName is unique #13578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add do...while loop in the SetValue method of SerializationResourceManager.cs until resourceName is unique #13578
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that SetValue
in SerializationResourceManager.cs
repeatedly generates a new resourceName
until it’s unique, fixing duplicate suffixes when serializing collections.
- Replaces single conditional append with a
do…while
loop to retry name generation - Changes the existence check from
TryGetValue
on the base name toContainsKey
on the currentresourceName
- Updates how
count
is retrieved and used when building the new name
Comments suppressed due to low confidence (1)
src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ResourceCodeDomSerializer.SerializationResourceManager.cs:787
- Because
count
is appended before it’s incremented, the first generated name can benameBase0
whenappendCount
is true but no existing entries are found. Movecount++
before formattingresourceName
(or restructure the loop) so the suffix starts at 1.
resourceName = $"{nameBase}{count}";
...omponentModel/Design/Serialization/ResourceCodeDomSerializer.SerializationResourceManager.cs
Outdated
Show resolved
Hide resolved
…nager.cs until resourceName is unique
3395dff
to
55afccb
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13578 +/- ##
===================================================
- Coverage 76.59901% 76.59527% -0.00375%
===================================================
Files 3230 3230
Lines 639161 639217 +56
Branches 47297 47304 +7
===================================================
+ Hits 489591 489610 +19
- Misses 145988 146038 +50
+ Partials 3582 3569 -13
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
All LGTM! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
…nager.cs until resourceName is unique (dotnet#13578) * Add do...while loop in the SetValue method of SerializationResourceManager.cs until resourceName is unique * Check nameBase directly rather than resourceName for clarity
/backport to release/8.0 |
Started backporting to release/8.0: https://github.com/dotnet/winforms/actions/runs/15725589917 |
/backport to release/9.0 |
Started backporting to release/9.0: https://github.com/dotnet/winforms/actions/runs/15725601101 |
Fixes #12595
Root Cause
This issue is caused by replacing
for (;;)
withif (appendCount || _nameTable.TryGetValue(nameBase, out count))
in PR #8332, which leads to resource name conflicts.Proposed changes
Customer Impact
Regression?
Risk
Screenshots
Before
Paste after the second time, the resource will end up using the same number 1 over and over

After
Resource suffixes are increasing
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow