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不一定是唯一,有时可能需要具体问题具体分析,但都可以从这个更新包入手
相关推荐
Sakura_j_h_5 小时前
Python 在定时任务里输出 emoji,UnicodeEncodeError 从哪来
开发语言·字符编码·windows·python·定时任务
隔窗听雨眠9 小时前
PostgreSQL单表从Windows迁移到Linux:差异剖析、方案对比与全流程实战
linux·windows·postgresql
Helix25011 小时前
Ansible混合环境自动化:Windows与Linux统一配置管理实战
windows·自动化·ansible·playbook·配置管理·winrm·混合环境
Java开发追求者13 小时前
windows快速安装docker
windows·docker·安装·1024程序员节
Helix25016 小时前
Windows ETW与KQL实战:终端性能诊断与遥测数据分析指南
windows·性能诊断·kql·etw·azure monitor·遥测数据·tracert
陈葛杰17 小时前
Adobe Premiere Pro2025安装教程
windows·adobe·开源软件·1024程序员节
承渊政道19 小时前
iOS远程控制电脑用什么好?iPhoneiPad远程控制Windows电脑最佳方案2026横评
windows·ios·远程控制·1024程序员节·iphone ipad
易点云徐源19 小时前
PDF 默认打开方式刚修好,过一分钟又变成“未知应用”?使用 ProcMon 成功抓出后台程序
windows·pdf
我是大猴子20 小时前
py how claude work项目分析
运维·服务器·windows·1024程序员节
paul_chen211 天前
解决Windows “此电脑”出现两个“图片”文件夹的问题
windows