Skip to content

TypeConverter isn't working for ModifierKeys #27528

@ericstj

Description

@ericstj

Reported by @onovotny, /cc @vatsan-madhavan-msft

Create a WPF application with a combination used in KeyBinding.Modifiers. For example:

    <Window.InputBindings>
        <KeyBinding Modifiers="Control+Shift" Key="H" Command="ApplicationCommands.Help"/>
    </Window.InputBindings>

Run that application.

Expect: runs correctly
Actual: crashes on startup with callstack:

   at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)
   at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
   at System.ComponentModel.EnumConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   --- End of inner exception stack trace ---
   at System.ComponentModel.EnumConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at System.Windows.Baml2006.TypeConverterMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\System.Xaml\System\Xaml\Runtime\ClrObjectRuntime.cs:line 486
   --- End of inner exception stack trace ---
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
   at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1_0(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\MS\Internal\Threading\ExceptionWrapper.cs:line 104
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\MS\Internal\Threading\ExceptionWrapper.cs:line 37
   at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\Dispatcher.cs:line 3119
   at System.Windows.Threading.DispatcherOperation.InvokeImpl() in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\DispatcherOperation.cs:line 583
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\DispatcherOperation.cs:line 527
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\Shared\MS\Internal\CulturePreservingExecutionContext.cs:line 234
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\Shared\MS\Internal\CulturePreservingExecutionContext.cs:line 185
   at System.Windows.Threading.DispatcherOperation.Invoke() in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\DispatcherOperation.cs:line 438
   at System.Windows.Threading.Dispatcher.ProcessQueue() in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\Dispatcher.cs:line 2269
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\Dispatcher.cs:line 2507
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\Shared\MS\Win32\HwndWrapper.cs:line 345
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\Shared\MS\Win32\HwndSubclass.cs:line 494
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\MS\Internal\Threading\ExceptionWrapper.cs:line 104
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\MS\Internal\Threading\ExceptionWrapper.cs:line 37
   at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\Dispatcher.cs:line 3119
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\Dispatcher.cs:line 1447
   at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\Dispatcher.cs:line 1159
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\Shared\MS\Win32\HwndSubclass.cs:line 392
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\Dispatcher.cs:line 2480
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\Dispatcher.cs:line 2330
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\Dispatcher.cs:line 368
   at System.Windows.Threading.Dispatcher.Run() in F:\devdiv.dotnet\DotNet-Trusted\src\WPF\src\WindowsBase\System\Windows\Threading\Dispatcher.cs:line 327
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at keyBinding.App.Main()

It would appear that the typeconverter for handling these enum combinations isn't being honored.

We need to look into how that converter is actually hooked up and find out why it isn't working on .NETCore.

Repro app: keyBinding.zip

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions