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不一定是唯一,有时可能需要具体问题具体分析,但都可以从这个更新包入手
相关推荐
m0_535817559 分钟前
从0到1上手Claude Code:Windows安装+88api配置全流程
windows·gpt·node.js·claude·claudecode·88api
阿昭L3 小时前
Windows用户态hook技术总结
windows·逆向·hook
fengchengwu20126 小时前
Jupyter 安装与使用指南:从环境配置到效率翻倍
ide·windows·jupyter
呉師傅6 小时前
东芝e-STUDIO 3525ac提示黄色和品红色墨粉盒在耗尽前被更换。请重新插入之前的墨粉盒并用至耗尽如何操作
运维·windows·电脑
玖釉-7 小时前
二叉树展开为链表:从先序遍历到原地指针重排
c++·windows·算法·leetcode·链表
MinterFusion7 小时前
如何在Windows下查看某个文件的MD5和SHA256值(v0.1.0)
windows·md5·sha256·系统运维·明德融创
她说彩礼65万7 小时前
WPF视觉树 逻辑树
wpf
idolao9 小时前
Autodesk Alias AutoStudio 2025安装教程 Windows版:自定义路径指南
windows
霸道流氓气质10 小时前
Windows 图形界面配置 Ollama 镜像地址完整教程
windows·ollama
Cheng小攸10 小时前
2.隐藏账户
windows