.NET应用程序无法启动和接收XamlParseException

KMC*_*KMC 33 c# deployment wpf

我写了一个可以在我的开发PC(Window 7)上安装和工作的应用程序.

  • 开发环境:Window 7,VS2010 WPF C#,同时安装了.NET 4.NET 3.5

在其他客户端计算机(XP SP3,2和1)上,它安装没有错误,但无法启动.在任务管理器中,我可以看到应用程序在关闭之前会短暂占用内存.

我通过以下方式确保了我在开发PC和各种客户端XP机器上的.NET 3.5一致性:

  • 该应用程序面向.NET 3.5(或3.5客户端配置文件)
  • 使用VS2010 Installer进行部署:在启动条件下使用.NET 3.5
  • 在调试应用程序和安装程序项目期间,没有关于.NET兼容性的任何错误

eventvwr发现以下警告:

 ¬º?¿‡–Õ:   ¥ÌŒÛ
 ¬º?¿¥‘¥:   .NET Runtime
 ¬º?÷÷¿‡:   Œ?
 ¬º? ID:    1026
»’??:       2011-10-18
 ¬º?:       15:18:32
”?ªß:       N/A
º?À„ª?: WWW-9DB69D5A3AF
?Ë ˆ:
Application: Foo.exe
Framework Version: v4.0.30319
Description: ”…”?Œ¥æ?¥¶¿Ìµƒ“Ï?££¨?¯?Ã÷’÷?°£
“Ï?£–?œ¢: System.Windows.Markup.XamlParseException
?—’ª:
   ‘? System.Windows.Markup.XamlReader.RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri)
   ‘? System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   ‘? System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   ‘? System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   ‘? System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
   ‘? System.Windows.Application.LoadComponent(System.Uri, Boolean)
   ‘? System.Windows.Application.DoStartup()
   ‘? System.Windows.Application.<.ctor>b__1(System.Object)
   ‘? System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   ‘? MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   ‘? System.Windows.Threading.DispatcherOperation.InvokeImpl()
   ‘? System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   ‘? System.Threading.ExecutionContext.runTryCode(System.Object)
   ‘? System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
   ‘? System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   ‘? System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   ‘? System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   ‘? System.Windows.Threading.DispatcherOperation.Invoke()
   ‘? System.Windows.Threading.Dispatcher.ProcessQueue()
   ‘? System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   ‘? MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   ‘? MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   ‘? System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   ‘? MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   ‘? System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   ‘? MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   ‘? MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   ‘? System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   ‘? System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   ‘? System.Windows.Threading.Dispatcher.Run()
   ‘? System.Windows.Application.RunDispatcher(System.Object)
   ‘? System.Windows.Application.RunInternal(System.Windows.Window)
   ‘? System.Windows.Application.Run(System.Windows.Window)
   ‘? System.Windows.Application.Run()
   ‘? FooSoftware.App.Main()


”–?ÿ?¸?‡–?œ¢£¨«Î?Œ‘ƒ‘? http://go.microsoft.com/fwlink/events.asp µƒ?Ô÷??Õ÷ß?÷÷––ƒ°£
Run Code Online (Sandbox Code Playgroud)

有这个XamlParseException导致我的应用程序无法启动XP Window Machine.到底是怎么回事?

Sim*_*ier 83

XamlParseException是应用程序启动时出现问题时发生的一般错误.我建议你修改你的应用程序启动代码,以追踪真正发生的事情并获取,不仅是XamlParseException,还有内部异常,它们可以帮助你确定问题的根源.这是一个例子:

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            // hook on error before app really starts
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            base.OnStartup(e);
        }

        void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            // put your tracing or logging code here (I put a message box as an example)
            MessageBox.Show(e.ExceptionObject.ToString());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


pau*_*sm4 7

对于初学者来说,你实际上有更好的运气,如果你建立在VS2010 ..但实际上是有针对性较低版本的.NET(3.5,甚至2.0).

如果你发布一些代码肯定会有所帮助.

确保已复制应用程序的所有必需文件(app.config等).

此链接听起来类似:

在Windows 7计算机上编写/编译的.NET 4程序将无法在XP上运行

它指出了这些出色的故障排除技巧:

使用Fusion Log Viewer


Seb*_*ier 6

你可以远程调试.基本上,这是通过在目标计算机上安装远程调试服务器,然后在启动应用程序时从visual studio连接到它来完成的.可以在这里找到更多信息:http://msdn.microsoft.com/en-us/library/bt727f1t.aspx ,这里有一个有点老的教程:http://www.cprogramming.com/tutorial/visual_studio_remote_debugging.html

请注意,必须使用调试符号(pdbs)进行部署,并且调试的软件必须与您的代码所在的版本相同.


Alo*_*aus 6

虽然您的目标是.NET 3.5,但您的客户端安装了.NET 4并使用它.字符串

Framework Version: v4.0.30319
Run Code Online (Sandbox Code Playgroud)

告诉我这个.要强制您的客户端实际使用.NET 3.5,您应该将App.config添加到您的应用程序并添加:

<configuration>
   <startup>
      <supportedRuntime version="v2.0.50727"/>
   </startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)

可能是因为.NET 4以不同的方式处理您的XAML.您是否尝试让您的应用程序在.NET 4下运行?如果您没有提供App.config,那么您仍然使用.NET Framework 4测试您的应用程序,尽管您确实以.NET Framework 3.5为目标.如果您的客户端足够好,您可以让他创建一个转储文件,这样您就可以轻松地直接调试它.从SysInternals工具套件下载Procdump,并将其与您的应用程序一起发送给您的客户端.让他执行

procdump -ma -e -t -x foo.exe %temp%\dump.dmp
Run Code Online (Sandbox Code Playgroud)

这将为每个未处理的异常生成一个完整的进程转储,并在进程终止于%TEMP%目录时生成另一个.Visual Studio 2010获得了更好的转储分析支持,因此您应该能够在Visual Studio 2010中对其进行分析.如果这没有帮助,您可以下载Windbg(此处为 32位),加载转储并键入

!分析-v

看看最后一个例外是什么.这应该够了吧.加载正确的调试dll(sos.dll for .NET 2,3,3.5和clr.dll for .NET 4)可能存在托管扩展的问题,但是有很多在线教程如何做到这一点.除此之外,我建议在应用程序中添加异常处理程序,以便在应用程序以意外方式终止时获得一个不错的日志文件.

如果输出没有导致正确的堆栈,你可以使用!ClrStack和!Threads找出哪些线程在其堆栈上有异常.


小智 5

通常我所做的是将日志文件放在进程之间,这样我就知道程序的流程.

如果这是一个控制台应用程序,请放置Console.WriteLine(某个字符串),然后您可以将Console.ReadLine()放在最后以暂停程序的执行.