【问题标题】:WPF App won't start after installationWPF App 安装后无法启动
【发布时间】:2011-08-07 20:12:17
【问题描述】:

我正在开发一个或多或少的普通 WPF 应用程序。我在我的解决方案中添加了一个 Windows 安装项目,并从我的 WPF 应用程序中添加了项目输出。

运行安装程序后,我无法运行该软件(尽管它在 Visual Studio 2010 中运行良好。)只有一个短暂的等待期,然后应用程序安静地退出。 Windows 事件日志中出现以下错误。我对 WPF 开发相当陌生...知道我在这里缺少什么吗?

感谢您的帮助!

编辑:根据要求从 App.xaml 提供 xaml 代码。

<Application x:Class="MyApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
    </Application.Resources>
</Application>


Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Windows.Markup.XamlParseException
Stack:
   at System.Windows.Markup.XamlReader.RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
   at System.Windows.Application.LoadComponent(System.Uri, Boolean)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.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 System.Threading.ExecutionContext.runTryCode(System.Object)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   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 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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.InvokeImpl(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.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at MyApp.App.Main()

【问题讨论】:

  • 在这里看到一些相关代码确实有助于跟踪此类问题。
  • 您需要处理 App 类的 DispatcherUnhandledException 事件并写出 MessageStackTrace 属性,不仅是传递给事件处理程序的异常,还有它的InnerException 属性(遵循嵌套异常,直到InnerException 为空。写入日志文件,以便在应用程序关闭后进行检查。通常只有一个内部异常指出无法解析 XAML 的确切原因.
  • 乔尔,这完全解决了我的问题!只需要在某个地方注入诊断代码,而那个事件就是这样。原来我的安装程序缺少应用程序预期存在的文件。如果您发表评论作为答案,我会接受!

标签: wpf


【解决方案1】:

(来自 Joel B Fant,他无法发表评论作为答案)

您需要处理 App 类的 DispatcherUnhandledException 事件,并写出传递给事件处理程序的异常及其 InnerException 属性中的 Message 和 StackTrace 属性(遵循嵌套异常,直到 InnerException 为 null。写入日志文件,以便您可以在应用关闭后进行检查。通常只有一个内部异常指出无法解析 XAML 的确切原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    • 1970-01-01
    • 2018-06-29
    • 2020-12-04
    • 2019-03-12
    • 1970-01-01
    相关资源
    最近更新 更多