How can I debug XAML designer issues?
Asked Answered
B

1

5

I'm developing a UWP app with Visual Studio 2015, and one of the things I want to do use some sample data at design time.

Now, I've added a XAML file, set the build action as DesignDataWithDesignTimeCrateableTypes

My XAML is really straight forward here:

<local:Freead
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MyNamespace.Uwp.Windows.ViewModels" 
    xmlns:ad="clr-namespace:MyNamespace.Classifieds;assembly=LocalAngle.Uwp" 
    ItemName="Java books" 
    Description="Free to anyone that wants them. A little out of date, but would make a handy doorstop." 
    ContactDetails="01632 960000" 
    Latitude="52.22" Longitude="1.95">
</local:Freead>

However, the intellisense is giving me pale blue wavy line and a tooltip for that of:

Cannot create instance of "Freead".

Historically, I've been able to debug the XAML design issues by firing up another instance of Visual Studio, attaching, and setting to break on all exceptions, but no exceptions appear to be thrown here, so how can I debug why it cannot create an instance of the type? (Given the obvious has already been checked, i.e. there is a parameterless constructor, and solution does build)

Boffa answered 21/1, 2016 at 13:17 Comment(0)
R
8

I was having XAML Designer errors and tried the old pre-Visual Studio 2015 approach:

  • Close any open XAML Designer windows
  • Start up another VS 2015 instance
  • Attach to the "XDesProc.exe" process (for me there was only one)
  • Open the problematic XAML page in the designer in the original VS instance

My error was "Object not initialized", but it was quite quick to find the underlying problem. Fixing it was a bit more effort!

Rida answered 4/2, 2016 at 16:52 Comment(2)
I never remember this and I attach to devenv.exe :\ Thanks!Cnemis
When targeting Windows build 16299 or above, the process to attach to is different. You'll need to look for UwpSurface.exe for UWP projects and WpfSurface.exe for WPF projects. The entire process for debugging can be found here (there is a dropdown in the top left to select different versions of Visual Studio): learn.microsoft.com/en-us/visualstudio/xaml-tools/…Reconsider

© 2022 - 2024 — McMap. All rights reserved.