This error occurs in XAML when you have something like:
1 2 3 4 5 6 7 |
<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Core="clr-namespace:Company.Core;assembly=Company.Core"> ... <style x:Key="xxx" TargetType="{x:Type Core:SomeObject}"> ... </style></resourcedictionary> |
and the compiler cannot find the ‘SomeObject’ class. Now, you can safe yourself a few hours because this error is totally fake. There is no problem with the namespace or the XAML syntax. Just change the definition of the ‘core’ (whatever name in your context) alias to
1 2 3 4 5 6 7 |
<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Core="clr-namespace:Company.Core"> ... <style x:Key="xxx" TargetType="{x:Type Core:SomeObject}"> ... </style></resourcedictionary> |
and all will be well. For some reason when you refer to a class withing the same assembly you should not set the ‘assembly’.
Thanks man, I wish the numerous DataBinding tutorials out there had mentioned namespaces of the ObjectDataProvider windows. I spent an hour trying to find out my problem until this pointed me in the right direction. I’m not sure why VS2008 doesn’t just use the default namespace when looking for the binding source objects.
By Jay May 18, 2010 - 9:39 amThanks Francois. This would have been a huge time synch to figure out on my own.
By Adam Cataldo May 20, 2010 - 6:29 pmAlways happy to get feedback like this, thanks
By Francois May 21, 2010 - 8:00 amHuh- in VS 2010, I have found the exact opposite to be true. If I don’t include the assembly specification, then it throws a similar error. The only difference in my code is that I’m using a DataTemplate instead of a style.
By Daniel September 24, 2010 - 2:32 am