Skip to content

System.Windows.Forms.KeysConverter.ConvertFrom exception on .NET SDK 7.0 #7610

@Ashley-Li

Description

@Ashley-Li

.NET version

.NET SDK 7.0.100-rc.2.22417.1

Did it work in .NET Framework?

No

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes, it's a regression issue, cannot repro on .NET 6.0.

Issue description

When running the application with .NET 7.0, an exception pops up, but the same code does not have an exception on .NET 6.0. Please see below gif:
reproStep

This is the initial feedback ticket: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1590419

Steps to reproduce

  1. Create a .NET 7.0 WinForms application.
  2. Add below codes on Program.cs of the Main() method.
    Console.WriteLine($"Environment.Version: {Environment.Version}");
    const string keyCombination = "Ctrl + N";
    Console.WriteLine($"Converting {keyCombination}to keys");
    Console.WriteLine($"Converted keys are: {new KeysConverter().ConvertFrom(keyCombination)}");
  3. Right click the project and press "Alt+Enter" on keyboard , set the Output type of the application is Console Application.
  4. Build and run the application.

Or

  1. Open attached application : TestApp.zip
  2. Build and run the application(TestAppNET7).

Current Behaviors:
An exception dialog pops up, so the printout has missing result.
image

Call Stack:
System.Collections.Generic.KeyNotFoundException
HResult=0x80131577
Message=The given key 'N' was not present in the dictionary.
Source=System.Private.CoreLib
StackTrace:
at System.ThrowHelper.ThrowKeyNotFoundException[T](T key)
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at System.Windows.Forms.KeysConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at TestAppNET7.Program.Main() in C:\Users\v-huli7\Desktop\TestApp\TestApp\TestAppNET7\Program.cs:line 20

Expected Behaviors:
There's no exception dialog pops up and the printout results are correct.
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions