WPF COMException在启动时崩溃应用程序(今天开始)

我刚刚开始在应用程序启动时看到这个Exception,其中一个应用程序已经投入生产3年了。

System.TypeInitializationException: The type initializer for 'MS.Win32.Penimc.UnsafeNativeMethods' threw an exception. ---> System.Runtime.InteropServices.COMException: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)) at MS.Win32.Penimc.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid) at MS.Win32.Penimc.UnsafeNativeMethods.CreatePimcManager() at MS.Win32.Penimc.UnsafeNativeMethods..cctor() --- End of inner exception stack trace --- at MS.Win32.Penimc.UnsafeNativeMethods.CreateResetEvent(IntPtr& handle) at System.Windows.Input.PenThreadWorker..ctor() at System.Windows.Input.PenThreadPool.GetPenThreadForPenContextHelper(PenContext penContext) at System.Windows.Input.PenThreadPool.GetPenThreadForPenContext(PenContext penContext) at System.Windows.Input.StylusWisp.WispTabletDeviceCollection.UpdateTabletsImpl() at System.Windows.Input.StylusWisp.WispTabletDeviceCollection.UpdateTablets() at System.Windows.Input.StylusWisp.WispTabletDeviceCollection..ctor() at System.Windows.Input.StylusWisp.WispLogic.get_WispTabletDevices() at System.Windows.Input.StylusWisp.WispLogic.RegisterHwndForInput(InputManager inputManager, PresentationSource inputSource) at System.Windows.Interop.HwndStylusInputProvider..ctor(HwndSource source) at System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters parameters) at System.Windows.Window.CreateSourceWindow(Boolean duringShow) at System.Windows.Window.CreateSourceWindowDuringShow() at System.Windows.Window.SafeCreateWindowDuringShow() at System.Windows.Window.ShowHelper(Object booleanBox) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at APSSSentinel.App.Main() 

显然,一些使用VS2017获得安装了.NET 4.7的Windows更新的开发人员也遇到了这种崩溃,现在看来推荐的解决方法是关闭触控支持。

https://developercommunity.visualstudio.com/content/problem/55303/visual-studio-may-terminate-unexpectedly-when-runn.html

在我的应用程序中,这并不理想。 有没有其他人遇到这个,并找到任何其他类型的解决方法?

更新:微软现在已经在手动更新中解决了这个问题 (如Jürgen所述), 我个人会坚持使用解决方法直到修复程序处于自动更新状态,因为要让每个用户安装手动更新都需要做大量工作。


这显然是.Net 4.7中的一个错误,它会影响具有触摸输入设备的Windows 7和8 / 8.1系统。 因此,人们可以希望Microsoft在未来的更新中解决这个问题。 同时,保留完整function的唯一方法是卸载并隐藏更新。

其他选项是在app.config中禁用stylys和触摸支持(如在链接中)或在代码中使用4.6或更高版本编译应用程序。 你没有说明为什么不理想,但我认为需要这些function? 请注意,禁用并不意味着每个应用程序都无法使用触摸设备,而是仅使用可通过鼠标访问的function。 更新:显然,没有鼠标的触摸设备用户将无法使用需要滚动的UI。

以下是那些来这里寻求快速修复的代码示例:

在App.config中(适用于使用任何框架版本编译的应用程序)

      

在代码中(使用.Net Framework> = 4.6编译时)

 protected override void OnStartup(StartupEventArgs e) { AppContext.SetSwitch("Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport", true); base.OnStartup(e); } 

Microsoft同时修复了.NET 4.7的问题,请参阅https://support.microsoft.com/en-US/help/4033488/comexception-error-from-wpf-applications-after-the-net-framework-4- 7-i的