Error while MergingDictionaries in Silverlight

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

In my SIlverlight application I used following code to perform the merge of Resources which are stored in some dedicated assembly designed for this purpose. For this reason I used following code:

ResourceDictionary dict = new ResourceDictionary();

string src = “/MySilverlightControls;component/themes/MyDictionary.xaml”

dict.Source = new Uri(src, UriKind.RelativeOrAbsolute);

Application.Current.Resources.MergedDictionaries.Add(dict);


This code usually works perfect. However sometimes it fails with following exception:

Error HRESULT E_FAIL has been returned from a call to a COM component.

This nothing saying exception does not help and do not try do decrypt the hidden information. I figured out that following code does a bit better job.

string src = “/MySilverlightControls;component/themes/MyDictionary.xaml”.

StreamResourceInfo resourceInfo =
Application.GetResourceStream(new Uri(src, UriKind.RelativeOrAbsolute));

StreamReader resourceReader = new StreamReader(resourceInfo.Stream);

string xaml = resourceReader.ReadToEnd();

ResourceDictionary resourceTheme = XamlReader.Load(xaml) as ResourceDictionary;

Application.Current.Resources.MergedDictionaries.Add(resourceTheme);

When using this code you will get the real error description. In my case this was indication that I had some error in XAML, which designer didn’t discover:

Invalid attribute value Daenet_Silverlight_Controls:WindowControl for property TargetType. [Line: 377 Position: 54]

To solve this specifi problem I added missing declaration:

xmlns:Daenet_Silverlight_Controls="clr-namespace:Daenet.Silverlight.Controls;assembly=Daenet.Silverlight"


Posted Jan 26 2010, 02:25 PM by Damir Dobric
Filed under:
developers.de is a .Net Community Blog powered by daenet GmbH.