Bugged by a very old bug

.991 Net Wpf

I ran into a very old bug which bugged me when I started using Prism last year: sometimes the xaml file cannot be found anymore at runtime, which was related to some overactive cleaning of files. Then I have to change the XAML file, so it’s regenerated again for the next build…

Do you happen to have a reproducible test case for this?

Not yet. From my memory it happend a lot more often last year. Now it did happen only twice in a few days. But it did happen with a newly generated project where I had made only minor changes… If I can gather more specific info I’ll let you know…

For future reference, this is the stacktrace. I now get it after I had to terminate VS2010 because it was locked up. Second thing I noticed: the resulting exe is about 10Kb smaller in size, which is about the sum of the xaml-files of this project. So it seems NO xaml-files are included.

I changed another .pas file belonging to a XAML-file (not the mainwindow.xaml that was reported as missing), and it runs again.

I also noticed that if during runtime an error occurs due to an invalid xaml-file (like a size-tag with wrong content), the debugger cannot find the xaml-file because it points to the main solution folder instead of the project folder.

System.IO.IOException was unhandled
  Message=Cannot locate resource 'mainwindow.xaml'.
  Source=PresentationFramework
  StackTrace:
       at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)
       at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
       at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
       at System.Windows.Application.DoStartup()
       at System.Windows.Application.<.ctor>b__1(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run()
       at AblKas2012.App.Main()
  InnerException: 

I’ve been unable to reproduce this. The next time you see it, if you could send me both a broken EXE as well as a working one for comparison, I’ll do my best to track it down.