The Stuff of Nightmares
Today I came across what seemed like a real showstopper in SL2. I was attempting to add a TabControl to a UserControl. All seemed to work well in the designer, but at runtime I would get two fairly vague exceptions:
and..
The second exception clearly pointed to where I had added the TabControl, but didn't really tell me what was going on.
I was pretty sure I'd seen the TabControl working before, so I opened up a new solution and copied the Xaml over. Below are the snippets chopped out of both solutions – no real difference here, but strangely the isolated solution worked!
Isolated Solution (works):
Original Solution (throws exceptions):
The Solution
After a while I realized I had the exact same problem some weeks ago and is nothing to do with the TabControl – it is to do with references!
Isolated Solution (works)
Here, the TabControl (which needs System.Windows.Controls.Extended) is instantiated within the startup project.
Original Solution (throws exceptions)
See the problem?
It turns out the startup project
is missing the reference to System.Windows.Controls.Extended. The original exception "The given key is not present in the dictionary" is about not being able to resolve the xmlns:my="clr-namespace:...;assembly=System.Windows.Controls.Extended reference in the Xaml from the entry point of the application.
Since this is the second time this has happened to me, I thought it would be worthy of a blog!