System.TypeLoadException: Method 'GetSelection' in type 'MS.Internal.Automation.SelectionProviderWrapper' does not have an implementation
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
I found the exception `System.TypeLoadException: Method 'GetSelection' in type 'MS.Internal.Automation.SelectionProviderWrapper' does not have an implementation` has a sudden increase since June 28.

The target framework of my application is .NET Framework 4.7.2. And the .NET Framework on the users' machine who have this exception is 4.8 or 4.8.1.
Is the exception related to the this [patch of WPF](https://support.microsoft.com/zh-cn/topic/2023-%E5%B9%B4-6-%E6%9C%88-13-%E6%97%A5-kb5027117-%E9%80%82%E7%94%A8%E4%BA%8E-windows-10-version-21h2-%E5%92%8C-windows-10-version-22h2-%E7%9A%84-net-framework-3-5-%E5%92%8C-4-8-1-%E7%B4%AF%E7%A7%AF%E6%9B%B4%E6%96%B0-e3ce1af2-498c-4df3-9453-6fb50a01f631)?
### Reproduction Steps
The exception will occure when app starts up. But I can't reprocue this on my machine now althrough I have installed [the patch](https://support.microsoft.com/zh-cn/topic/2023-%E5%B9%B4-6-%E6%9C%88-13-%E6%97%A5-kb5027117-%E9%80%82%E7%94%A8%E4%BA%8E-windows-10-version-21h2-%E5%92%8C-windows-10-version-22h2-%E7%9A%84-net-framework-3-5-%E5%92%8C-4-8-1-%E7%B4%AF%E7%A7%AF%E6%9B%B4%E6%96%B0-e3ce1af2-498c-4df3-9453-6fb50a01f631).
### Expected behavior
No error
### Actual behavior
Error message:
```
System.TypeInitializationException: The type initializer for 'System.Windows.Automation.Peers.AutomationPeer' threw an exception. ---> System.TypeLoadException: Method 'GetSelection' in type 'MS.Internal.Automation.SelectionProviderWrapper' from assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
at System.Windows.Automation.Peers.AutomationPeer.Initialize()
at System.Windows.Automation.Peers.AutomationPeer..cctor()
--- End of inner exception stack trace ---
at System.Windows.Automation.Peers.AutomationPeer.RaiseFocusChangedEventHelper(IInputElement newFocus)
at System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp)
at System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
at System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
at System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
at System.Windows.Interop.HwndKeyboardInputProvider.OnSetFocus(IntPtr hwnd)
at System.Windows.Interop.HwndKeyboardInputProvider.FilterMessage(IntPtr hwnd, WindowMessage message, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
```
### Regression?
_No response_
### Known Workarounds
_No response_
### Impact
_No response_
### Configuration
_No response_
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.