Silverlight Error - Failed to assign to property 'System.Windows.ResourceDictionary.Source'

When you add resource dictionary files aka style files, you may run into following errors.


{System.Windows.Markup.XamlParseException: Failed to assign to property 
 'System.Windows.ResourceDictionary.Source'. [Line: 8 Position: 32]
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at SilverLayout.App.InitializeComponent()
   at SilverLayout.App..ctor()}

As the error indicates that there is something wrong related to Source property of ResourceDictionary object. Following example shows XAML snippet from my App.xaml file where I was trying to add a resource dictionary.


<Application.Resources>
 <ResourceDictionary>
  <ResourceDictionary.MergedDictionaries>
   <ResourceDictionary Source="Assets\LayoutStyles.xaml">
  <ResourceDictionary.MergedDictionaries>
 <ResourceDictionary>
<Application.Resources>

If you look at the code snippet there does not seem to be anything wrong with it. But I have marked part of it with RED. Yes, I accidently used BACK SLASH (\) in the path. Parser did not like that while resolving path to that dictionary file. To fix this problem I just has to switch to using FORWARD SLASH (/)


<Application.Resources>
 <ResourceDictionary>
  <ResourceDictionary.MergedDictionaries>
   <ResourceDictionary Source="Assets/LayoutStyles.xaml">
  <ResourceDictionary.MergedDictionaries>
 <ResourceDictionary>
<Application.Resources>

Search

Social

Weather

20.8 °C / 69.5 °F

weather conditions Clouds

Monthly Posts

Blog Tags