【问题标题】:WPF COMException Crashes Application At Startup (Started Today)WPF COMException 在启动时使应用程序崩溃(今天开始)
【发布时间】:2017-11-18 16:31:28
【问题描述】:

我今天刚刚开始在应用程序启动时看到这个异常,该应用程序已投入生产 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

对于我的应用程序,这并不理想。有没有其他人遇到过这种情况,并找到了任何其他解决方法?

【问题讨论】:

标签: c# wpf crash .net-4.7


【解决方案1】:

更新:Microsoft 现已在 manual update 中修复了此问题(如 Jürgen 所述),我个人将坚持使用该解决方法,直到修复在自动更新中,因为它让每个用户都安装手动更新需要做很多工作。


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

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

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

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

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

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

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

【讨论】:

  • 不幸的是,该应用程序主要用于甚至可能没有连接鼠标/键盘的触摸设备上,因此禁用触摸可能是不可能的,而不是不理想。我很欣赏这个建议,并认为这适用于大多数情况。
  • 可以用鼠标完成的正常操作在禁用后仍然有效。因此,触摸设备上的点击转化为点击。我想只有高级功能,比如多点触控和压力感应,是行不通的。
  • 在网格和列表框中滚动会产生一些不可预知的结果,所以我决定暂时在客户端机器上卸载和阻止 .NET 4.7。我处于一个独特的位置,我可以控制这一点,对于其他同样如此的人,您可能想要为相应的 KB 发出 WUSA 卸载命令。 blogs.msdn.microsoft.com/dotnet/2017/06/13/…
【解决方案2】:

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-06
  • 1970-01-01
相关资源
最近更新 更多