Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET application cannot start and receive XamlParseException

Tags:

c#

deployment

wpf

I wrote an app that can install and work on my development PC (a Window 7).

  • Development Environment: Window 7, VS2010 WPF C# with both .NET 4 and .NET 3.5 installed

On other client computer (XP SP3, 2 and 1), it install with no error, but can not start. In task manager, I can see the application takes up memory briefly before closing by itself.

I had made sure .NET 3.5 consistency across my develop PC and various client XP machines by following:

  • The application targets .NET 3.5 (or 3.5 Client Profile)
  • Use VS2010 Installer for deployment: targets .NET 3.5 in Launch Condition
  • No error whatsoever about .NET compatibility during debug of application and installer project

eventvwr caught the following warning:

 ¬º˛¿‡–Õ:   ¥ÌŒÛ
 ¬º˛¿¥‘¥:   .NET Runtime
 ¬º˛÷÷¿‡:   Œfi
 ¬º˛ 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 µƒ∞Ô÷˙∫Õ÷ß≥÷÷––ƒ°£

there was this XamlParseException causing my app to not start on XP Window Machine. What is going on?

like image 947
KMC Avatar asked Oct 18 '11 03:10

KMC


5 Answers

XamlParseException is the generic error that happens when there is a problem at application start. I suggest you modify you application startup code to trace what's really going on and get, not only the XamlParseException, but also the inner exception(s) which should help you determine the root of the problem. Here is an example:

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());
        }
    }
}
like image 60
Simon Mourier Avatar answered Nov 16 '22 05:11

Simon Mourier


For starters, you'd actually have better luck if you built on VS2010 .. but actually targeted for a lower version of .Net (3.5, or even 2.0).

It would definitely be helpful if you post a bit of code.

Make sure you've copied all the necessary files for your application (app.config, etc).

This link sounds similar:

.NET 4 Program written/compiled on Windows 7 machine won't run on XP

And it points to these excellent troubleshooting tips:

Using Fusion Log Viewer

like image 44
paulsm4 Avatar answered Nov 16 '22 05:11

paulsm4


You can remote debug. Basically this is done by installing the remote debug server on the target machine, then attach to it from your visual studio when you start the application. Some more info can be found here : http://msdn.microsoft.com/en-us/library/bt727f1t.aspx and there's a somewhat elderly tutorial here : http://www.cprogramming.com/tutorial/visual_studio_remote_debugging.html

Please note that you must deploy with debug symbols (pdbs) and the software debugged must be in the same version that your code is in.

like image 6
Sebastian Edelmeier Avatar answered Nov 16 '22 04:11

Sebastian Edelmeier


Although you were targetting .NET 3.5 your client hat .NET 4 installed and used it. The string

Framework Version: v4.0.30319

does tell me this. To force your client to actually use .NET 3.5 you should add an App.config to your application and add:

<configuration>
   <startup>
      <supportedRuntime version="v2.0.50727"/>
   </startup>
</configuration>

It could be that you are getting an exception because .NET 4 treats your XAML in a different way. Did you try to let your application run under .NET 4? If you have no App.config supplied you did test your application with .NET Framework 4 anyway although you did target .NET Framework 3.5. If your client is nice enough you can let him create a dump file so you have an easy way to debug it directly. Download Procdump from the SysInternals tool suite and send it along with your application to your client. The let him execute

procdump -ma -e -t -x foo.exe %temp%\dump.dmp

This will generate a full process dump for every unhandled exception and another one when the process terminates into the %TEMP% directory. Visual Studio 2010 has gotten much better dump analysis support so you should be able to analyze it within Visual Studio 2010. If that does not help you can download Windbg (32 bit here), load the dump and type

!analyze -v

to see what the last exception was. That should do the trick. There may be issues with the managed extensions to load the right debugging dll (sos.dll for .NET 2,3,3.5, and clr.dll for .NET 4) but there are plenty of tutorials online how to do it. Besides this I would recommend to add exception handlers into your application so you get a nice log file when your application does terminate in an unexpected way.

If the output did not lead to the right stack you shold use !ClrStack and !Threads to find out which threads have exceptions on their stack.

like image 6
Alois Kraus Avatar answered Nov 16 '22 04:11

Alois Kraus


Usually what I do is put log files in between processes so I know the flow of my program.

If this is a console application, put Console.WriteLine(some string) and then you can put Console.ReadLine() at the end to pause the execution of your program.

like image 5
Jonats Avatar answered Nov 16 '22 04:11

Jonats