WPF启动失败报System.Windows.Automation.Peers.AutomationPeer.Initialize()错误解决

问题描述

win10系统上WPF程序启动后就崩溃,通过查看崩溃日志如下:

应用程序: xxx.exe

Framework 版本: v4.0.30319

说明: 由于未经处理的异常,进程终止。

异常信息: System.TypeLoadException

在 System.Windows.Automation.Peers.AutomationPeer.Initialize()

在 System.Windows.Automation.Peers.AutomationPeer...cctor()

这里是引用

异常信息: System.TypeInitializationException 在

System.Windows.Automation.Peers.AutomationPeer.RaiseFocusChangedEventHelper(System.Windows.IInputElement)

System.Windows.Input.KeyboardDevice.ChangeFocus(System.Windows.DependencyObject,

Int32) 在

System.Windows.Input.KeyboardDevice.TryChangeFocus(System.Windows.DependencyObject,

System.Windows.Input.IKeyboardInputProvider, Boolean, Boolean,

Boolean) 在

System.Windows.Input.KeyboardDevice.Focus(System.Windows.DependencyObject,

Boolean, Boolean, Boolean) 在

System.Windows.Input.KeyboardDevice.Focus(System.Windows.IInputElement)

在 System.Windows.Interop.HwndKeyboardInputProvider.OnSetFocus(IntPtr)

System.Windows.Interop.HwndKeyboardInputProvider.FilterMessage(IntPtr,

MS.Internal.Interop.WindowMessage, IntPtr, IntPtr, Boolean ByRef) 在

System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr, Int32,

IntPtr, IntPtr, Boolean ByRef) 在

MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean

ByRef) 在

MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) 在

System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,

System.Object, Int32) 在

System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object,

System.Delegate, System.Object, Int32, System.Delegate) 在

System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority,

System.TimeSpan, System.Delegate, System.Object, Int32) 在

MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

解决方案:

方案一:升级windows系统

如果当前系统有升级,手动升级系统,一般系统问题都可以通过升级来解决

方案二:卸载windows更新

通过查找资料和猜测,可能是windows更新导致了这个问题,其中github中也有这个问题:
https://github.com/dotnet/wpf/issues/8056

再和我当前有问题的这台电脑比较,发现了这个更新可能有问题:KB5011048

卸载后重启,软件正常。

备注:

  1. 如果发现软件今天运行正常,第二天再运行时出现如上错误,大概率就是更新出现了问题,可以通过这个方法去排除。
  2. KB5011048不一定是唯一,有时可能需要具体问题具体分析,但都可以从这个更新包入手
相关推荐
LZQqqqqo1 小时前
C# _列表(List<T>)_ 字典(Dictionary<TKey, TValue>)
windows
Channing Lewis3 小时前
zoho crm为什么xx是deal的关联对象但是调用函数时报错说不是关联对象
运维·服务器·windows
李小咖3 小时前
第2章 cmd命令基础:常用基础命令(1)
windows·网络安全·cmd·cmd命令·李小咖
Digitally3 小时前
6种将iPhone照片传输到Windows 10电脑的方法
windows·电脑·iphone
sean9084 小时前
Chrome 提示 “此扩展程序不再受支持”(MacOS/Windows)
chrome·windows·macos·扩展·支持
小乖兽技术8 小时前
C#开发基础之深入理解“集合遍历时不可修改”的异常背后的设计
开发语言·windows·c#
kyranhan9 小时前
WPF,窗口拖动事件与窗口内控件点击事件
wpf
gb42152879 小时前
负载均衡算法中的加权随机算法
windows·算法·负载均衡
未出道的小弟9 小时前
图形界面应用程序技术栈大全
windows
孟婆来包棒棒糖~20 小时前
SpringCloude快速入门
分布式·后端·spring cloud·微服务·wpf