developers.de
daenet's .NET Community

Error while MergingDictionaries in Silverlight

Damir Dobric Posts

 

Damir@Phone    



My upcoming sessions:

AppFabric Applications at
NRW Conf 2011
09.Sept.2011 Wuppertal

HTML5 widgets in WP7+
Monodroid
Mobility Day
21.Sept.2011 - Zagreb

AppFabric and WCF sessions at
Advanced Developer Conference
26.-27. Oktober 2011 in Frankenthal

AppFabric Applications, queues, topics and more at
Prio Conference
02. - 03. November 2011 in Meistersingerhalle Nürnberg

AppFabric Applications deep dive hosted by
.NET User Group Frankfurt
17.Nov.2011 18.30-22.30 Microsoft - Bad Homburg 

 

 

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:

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
daenet GmbH