0

我正在使用这种方法在我的 WPF 应用程序中注册一个全局热键。它在调试或从 Visual Studio 运行时工作正常,但在使用 Visual Studio 安装程序项目发布应用程序并将其安装到我的 PC 后,应用程序会引发以下错误(来自事件查看器)。

我尝试过的事情:

  • 以管理员身份运行,
  • 禁用 Windows Defender,
  • 在另一台没有防病毒软件的 Windows 10 PC 上运行
  • 在 x86 配置中构建

错误信息:

Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException
   at MS.Internal.AppModel.ResourcePart.GetStreamCore(System.IO.FileMode, System.IO.FileAccess)
   at System.IO.Packaging.PackagePart.GetStream(System.IO.FileMode, System.IO.FileAccess)
   at System.IO.Packaging.PackagePart.GetStream()
   at System.Windows.Application.LoadComponent(System.Uri, Boolean)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1_0(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at MyAppName.App.Main()

其次是:

Faulting module name: KERNELBASE.dll, version: 10.0.18362.778, time stamp: 0x692cf0ab
Exception code: 0xe0434352
Fault offset: 0x00114192
Faulting process id: 0x274
Faulting application start time: 0x01d61fae9d4b314d
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report Id: d5ca4cee-54ea-4f22-a2e5-86674c74d942
Faulting package full name: 
Faulting package-relative application ID:
4

1 回答 1

0

问题确实是缺少 dll - app resources.dll。显然 WPF 应用程序总是附带文化文件夹(默认为 en-US)。它被复制到构建时的输出目录(.\bin\Debug\en-US),但 Visual Studio 安装程序不会选择它,必须手动添加。

它是在 VS Installer 项目的文件系统中完成的 -> 新项目输出...

在此处输入图像描述

于 2020-05-08T14:37:07.060 回答