MathLion Software

The online home for everything MathLion Software

Browsing Posts published in June, 2010

XamlParseException and Resources in WPF

No comments

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.

xamlparseerror screen capture

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:

xamlparseerror_detail

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

Object and Collection Initializers – VB.net

No comments

While doing some work on some DTO (Data Transfer Objects) code and I decided instead of making numerous overloads of the constructor for an object, I would provide basic one or two and additional construction options when using them will use the new Object Initializer code structure available.

I was looking for a good set of examples and the below blog post is pretty good so I am linking it here for me to find later.

Object and Collection Initializers – VB – Eric White’s Blog – Site Home – MSDN Blogs

Powered by WordPress Web Design by SRS Solutions © 2010 MathLion Software Design by SRS Solutions