【问题标题】:System.Windows.Markup.XamlParseExceptionSystem.Windows.Markup.XamlParseException
【发布时间】:2011-07-11 09:11:09
【问题描述】:

我已经编写了一个 WPF 应用程序,在我的计算机上它运行正常。 现在我正在尝试在 W7 计算机上部署 wpf 应用程序。并得到以下异常:

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 System.Windows.Application.Run()
   at CAMXSimulator.App.Main()

知道这里有什么问题吗?

谢谢

【问题讨论】:

  • 我遇到了完全相同的异常,并且无法在某些 Windows 上启动我的应用程序(在某些 Windows 上工作),您找到解决方案了吗?
  • 我也有同样的问题。我们在 VM 计算机上安装了我们的应用程序,并将远程桌面连接到它,并且 8 个帐户中有 2 个可以正常工作,其余的会出现该错误。所有帐户都是管理员并在计算机上运行相同的完全相同的 exe。所以我知道这与代码无关。它是某个地方缺失的用户。仅供参考,所有帐户都是本地管理员组的一部分。
  • 这就是我讨厌 XAML 的原因。

标签: c# .net wpf xaml


【解决方案1】:

当您的主窗口构造函数或加载操作的某些部分失败时,这种类型的异常很常见。如果您可以掌握堆栈跟踪,请查看内部异常,您可能会发现真正的问题。

【讨论】:

    【解决方案2】:

    我遇到了这个问题,因为我在 Application 构造函数中显示了一个表单。此表单使用 Style="{StaticResource XYZ}"。此静态资源是在应用程序的 XAML 文件中定义的。

    我通过在应用程序的稍后阶段显示表单解决了这个问题,此时应用程序对象已完全构建。

    【讨论】:

    • 非常感谢您的解释 - 有同样的问题,解决方案 - 和你在这里伤心的完全一样,非常感谢!
    【解决方案3】:

    我有同样的异常报告。我可以通过使用windbg 程序来解决它。

    • 下载windbg x86(非x64)版本。
    • 在其中打开应用程序的.exe文件(文件菜单->打开exe。)
    • 运行这些命令来查看真正的异常:

    经过分析,我发现系统中缺少System.Net.Http.Formatting程序集。

    0:000> g
    0:000> sxe clr
    0:000> g
    0:000> !loadby sos clr
    0:000> !CLRStack
    0:000> !PrintException
    
    Exception type: System.IO.FileNotFoundException
    Message: Could not load file or assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
        InnerException: <none>
    

    【讨论】:

      【解决方案4】:

      我唯一能想到的是两个盒子上是否有相同的 .NET 版本。 NET 4 有一些 3.5 SP1 没有的新特性(重新 XAML 解析器)

      【讨论】:

        【解决方案5】:

        在干净的机器上安装 ClickOnce 应用程序时,我注意到了类似的行为。我通过设置应用程序的要求来解决安装 .Net 4 和 .Net 3.5 full 的要求。

        它不再发生了。

        【讨论】:

        • 我遇到了完全相同的异常。但在 VS2010 中,我只能针对一个框架(3.5 或 4),但不能同时针对两者。 “两者”是什么意思?我安装了 3.5 和 4 FrameWork,但应用似乎仍然无法启动。
        • 对于“两者”,我指的是“发布”属性页面中的应用程序“先决条件”。例如,我有一个针对 .Net 4(完整)的应用程序,但也需要 .Net 2(由于第 3 方 dll)。在“先决条件”列表中,我检查了:3.5-SP1、4、4-客户端配置文件。但是,我很确定这不是选择这些框的正确方法!
        【解决方案6】:

        确保在目标机器上运行时构建在正确的 x86 或 x64 架构中。我也面临同样的问题,该应用程序能够在我的拇指驱动器 FAT32 上运行,但是它在另一台装有 Windows 7 - 32 位的机器上失败了(我知道 32 位的 Windows 7 很奇怪)见 http://social.msdn.microsoft.com/Forums/vstudio/en-US/8f803f28-dfda-4be5-9e8d-f7d82db95961/c-wpf-systemwindowsmarkupxamlparseexception?forum=wpf

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-03-18
          • 1970-01-01
          • 2017-09-20
          • 1970-01-01
          • 2017-10-18
          相关资源
          最近更新 更多