-
Couldn't load subscription status.
- Fork 1.1k
Description
-
.NET Core Version: 3.1.2
-
Have you experienced this same bug with .NET Framework?: No
Problem description:
Steps to reproduce:
- Create a blank .NET Framework WinForms application with a Form.
- Set the Form to
Localizable = truein the designer. - Add context menu with single item.
- Set the
ShortcutKeyson the item toControl+C. - Observe that the application works just fine on .NET Framework 4.8.
- Switch locale at startup to German by
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE"); - Observe that the application still starts just fine on .NET Framework 4.8.
- Change the application to target
netcoreapp31and it immediately crashes on startup.
The reason for the crash is that the .resx file contains the shortcut key serialized as
<data name="booToolStripMenuItem.ShortcutKeys" type="System.Windows.Forms.Keys, System.Windows.Forms">
<value>Ctrl+C</value>
</data>
Notice that the serialized value starts with Ctrl, not Control. It is produced and consumed by KeysConverter class that is locale dependent. While the value Control would work in any locale due to the fallback to names in the Keys enum the value Ctrl is taken from a dictionary that contains localized names. On .NET Core 3.1 in the German localization the name for Control key is Strg. Thus the value Ctrl+C in the resource file is invalid and causes conversion error at runtime.
Notably we migrated a large project from .NET Framework to .NET Core where we hit this issue. The .NET Framework also has similar issue in code but the localizations may differ which would explain why the problem is not hit.
Manually fixing the value in the .resx file to Control+C makes the application work in any locale but any further editing in the designer breaks it again.
Expected behavior:
No crash. The resources generated by the designer should be locale independent.
Minimal repro:
Here's the sample app created using the steps above. It is multi-targeting both .NET Framework and .NET Core so it can run in both variation from inside Visual Studio.