-
Notifications
You must be signed in to change notification settings - Fork 991
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
ResourceCodeDomSerializer fails to assign distinct number suffixes to resources when serializing collection values #12595
Comments
@Olina-Zhang can you work with this customer to build up some sort of repro scenario? |
@codereader I tried to repro your issue, .NET 9 and .NET framework apps have the same result with a sample app: Can you please help to see if is that your issue? |
Hello, thanks for taking the time to look into this :) The ZIP file doesn't quite reproduce the problem. It differs by two points: First, the
In the current .NET 9 serializer, the line reads like this:
See Line 741 in 7a4fa49
Second, in my production scenario, the I attached a project, where I adjusted the .NET 9 version to reproduce the problem. Clicking the button should yield the following result: nameBase btnControl => generated ResourceName = btnControl1 Note the same resource name being generated for the same nameBase values (starting from the third invocation). |
@codereader It seems you forgot to upload your project, can you please provide it? I will use it for testing again. Thanks! |
I created another project to repro this issue, if use Please see following video: ResourceIssue.mp4Repro app: WinFormsApp19.zip |
Yikes, apologies for this classic mistake. I attached the project now. I checked your video, yes, this looks more like the behaviour I am seeing. If you run the .NET 9 project in my ZIP, you should see very similar output. Thanks for taking the extra time. |
.NET version
8.0.201 (the affected code is still there in .NET 9)
Did it work in .NET Framework?
Yes
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No response
Issue description
The code in ResourceCodeDomSerializer.SerializationResourceManager.SetValue() (around code lines 714) is failing when assigning sequential number suffixes to resource names:
While I cannot provide an quick-and-easy project to reproduce this, I'd like to suggest reading the code instead:
The code in .NET 4.8 assigned numbers starting from 1..N (even if only one value was in the _nameTable, so from the comment in the code I assume it has been changed to avoid assigning a number to the very first occurrence.
The bug occurs when generating number suffixes for the same
nameBase
value more than twice - it will end up using the same number 1 over and over. You'll end up with a _nameTable looking like this:"name1" will be overwritten every time after the second.
Steps to reproduce
The bug is recurring in our software when copy/pasting WinForms controls in design mode. We are maintaining a Window Editor application which allows to copy/paste controls. When serializing the controls, the CodeDomSerializer will end up generating code like this (note the resource names, which are always using the number 1 as suffix.
The text was updated successfully, but these errors were encountered: