So being fairly new to WPF when I got a XamlParseException when debugging an application I am developing I did search online, as it wasn’t exactly clear at first what was wrong. The capture below shows the error message, click for bigger view.
So I made a dash to the internet and did a search for information on this. The first result I found was a 2007 post from Laurent Bugnion which talks about wrapping the call to InitalizeComponent() in a Try-Catch to get access to the InnerException and StackTrace. This lead me to realize I should look closer at the exception I am getting. Yes I know I should have done that FIRST! So when I clicked on the “View Detail…” link in the above capture I got this:
As you can see in the highlighted part of the screenshot the error was an error introduced when I changed a converter class I had created to format a datetime into a string of a particular format. I changed the name of it to be more descriptive, and also made a similar one that outputs into a different format. I did a Search/Replace on the name of the one I was using and updated them to the new ones I wanted to use. The issue is that in one Xaml I forgot to add the NEW converter to the <Resources> section of the file, which is why it could not be found when it was trying to parse the Xaml at runtime.
I simply changed:
<UserControl.Resources>
<my:JustDateConverter x:Key=”JustDateConverter”/>
to
<UserControl.Resources>
<my:JustDateConverter x:Key=”JustDateConverter”/>
<my:FullDateConverter x:Key=”FullDateConverter”/>
to include the new converter and all is well again.
So what’s the take away(s) on this post, beside the fact I can ramble at times?
- ALWAYS be sure to view the details of any error messages you get
- when you get a XamlParseException thrown, be sure to check if you have all the resources referenced you are trying to use
More From MathLion Software
- Links on Silverlight PivotViewer
- Should NuGet be used by third party control makers?
- Object and Collection Initializers – VB.net
MathLion Software Recommends
- What’s the good and the bad? (Ignite Phoenix)
- Right Click, Copy and Paste (Voices of Arizona)
- Ignite Phoenix 4 – Recap and notes (Ignite Phoenix)
