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不一定是唯一,有时可能需要具体问题具体分析,但都可以从这个更新包入手
相关推荐
wanghowie10 分钟前
01.04 Java基础篇|泛型、注解与反射实战
java·开发语言·windows
大猫和小黄10 分钟前
Windows环境下在VMware中安装和配置CentOS 7
linux·windows·centos
深圳佛手13 分钟前
Java大对象(如 List、Map)如何复用?错误的方法是?正确的方法是?
java·jvm·windows
奋斗的好青年24 分钟前
Ubuntu+Windows双系统修复引导+更改启动顺序
linux·windows·ubuntu
我的golang之路果然有问题27 分钟前
win键盘设置改为类似mac 配置
windows·笔记·macos·计算机外设·键盘
yiSty33 分钟前
Windows 10/11下安装WSL Ubuntu
linux·windows·ubuntu
YJlio36 分钟前
2025 我用 Sysinternals 打通 Windows 排障“证据链”:开机慢 / 安装失败 / 磁盘暴涨(三个真实案例复盘)
人工智能·windows·笔记
Miketutu1 小时前
Dart基础学习
开发语言·windows
feiduoge9 小时前
教程 44 - 相机系统
windows·游戏引擎·图形渲染
松涛和鸣10 小时前
Linux Makefile : From Basic Syntax to Multi-File Project Compilation
linux·运维·服务器·前端·windows·哈希算法