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不一定是唯一,有时可能需要具体问题具体分析,但都可以从这个更新包入手
相关推荐
iangyu25 分钟前
【windows server脚本每天从网络盘复制到本地】
开发语言·windows·php
love530love2 小时前
家用或办公 Windows 电脑玩人工智能开源项目配备核显的必要性(含 NPU 及显卡类型补充)
人工智能·windows·python·开源·电脑
绿龙术士3 小时前
构建现代化WPF应用:数据驱动开发与高级特性解析
c#·wpf
周胡杰15 小时前
鸿蒙接入flutter环境变量配置windows-命令行或者手动配置-到项目的创建-运行demo项目
javascript·windows·flutter·华为·harmonyos·鸿蒙·鸿蒙系统
几道之旅19 小时前
分别在windows和linux上使用curl,有啥区别?
linux·运维·windows
一直奔跑在路上20 小时前
【Ansible】基于windows主机,采用NTLM+HTTPS 认证部署
windows·https·ansible
郭逍遥20 小时前
[工具]B站缓存工具箱 (By 郭逍遥)
windows·python·缓存·工具
x-cmd21 小时前
[250512] Node.js 24 发布:ClangCL 构建,升级 V8 引擎、集成 npm 11
前端·javascript·windows·npm·node.js
IT空门:门主1 天前
本地的ip实现https访问-OpenSSL安装+ssl正式的生成(Windows 系统)
windows·https·ssl
安装虚拟机的老师傅1 天前
【2025最新】Windows系统装VSCode搭建C/C++开发环境(附带所有安装包)
c语言·windows·vscode·其他