WPF COMException在启动时崩溃应用程序(今天开始) [英] WPF COMException Crashes Application At Startup (Started Today)

查看:137
本文介绍了WPF COMException在启动时崩溃应用程序(今天开始)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天才开始使用已经生产了3年的应用程序在应用程序启动时在野外看到这种异常。

I have just today started seeing this Exception out in the wild on application launch with an app that has been in production for 3 years.

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的开发人员在安装Windows Update并安装.NET 4.7时也遇到了此崩溃,看来目前建议的解决方法是关闭触摸支持。

Apparently, some developers using VS2017 who got a Windows update that installed .NET 4.7 have been getting this crash as well, it appears the recommended workaround for now is to turn touch support off.

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

对于我的应用程序,这并不理想。

With my application, this is not ideal. Has anyone else run into this, and found any other sort of workaround?

推荐答案

更新:Microsoft现在已解决此问题。 手动更新 (如Jürgen所述),我个人会坚持使用该解决方法,直到该修复程序处于自动更新中,因为这将需要大量工作



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

Update: Microsoft has now fixed this problem in a manual update (as noted by Jürgen), personally I will stick with the workaround until the fix is in the automatic update because it would be a lot of work to make every user install a manual update.


This is obviously a bug in .Net 4.7 that affects Windows 7 and 8/8.1 systems that have a touch input device. Therefore one can hope that Microsoft addresses this in a future update. Meanwhile the only way to retain full functionality is by uninstalling and hiding the update.

其他选项是禁用样式并触摸app.config中的支持(例如您的链接) )或代码(如果该应用使用4.6或更高版本进行了编译)。您没有指定为什么不理想,但我认为需要这些功能?请注意,禁用功能并不意味着每个应用程序都不能在触摸设备上使用,而是意味着它们仅使用鼠标可访问的功能。 更新:显然,没有鼠标的触摸设备用户在使用需要滚动的UI时会遇到麻烦。

Other option is disabling the stylys and touch support either in app.config (like in your link) or in the code if the app is compiled with 4.6 or newer. You didn't specify why that is not ideal but I assume those features are needed? Notice that the disabling doesn't mean that every app is unusable with touch devices, but rather that they only use features that are accessible with a mouse. Update: Apparently touch device users without a mouse will have trouble using UI that requires scrolling.

以下是此处寻求帮助的代码示例快速修复:

Here's the code examples for those who come here seeking quick fix:

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

In App.config (works with apps compiled with any framework version)

<configuration>
  <runtime>
    <AppContextSwitchOverrides value="Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true" />
  </runtime>
</configuration>

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

In code (when compiled with .Net Framework >= 4.6)

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

这篇关于WPF COMException在启动时崩溃应用程序(今天开始)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆