Globlal Resources Assembly

Topics: Prism v4 - WPF 4
Nov 4, 2012 at 2:21 PM
Edited Nov 4, 2012 at 2:23 PM


I'm trying to place some Resources in a separate assembly and use it globally in all my modules.

Here I post  a sample piece and sample source code which will point to my exact problem.

Project Name is : Resources

What is wrong with this ?

 Sample Piece :


                <ResourceDictionary Source="pack://application:,,,/Resources;component/Themes/Generic.xaml"/>

Download Link   (Editable) (Alternative- Not-Editable)

More Explanation :

On Design-Time it doesn't show any parsing error and seems to be correct.

Should I define it as a module, Do any registration and initialization via the Container ?

I saw the great sample you provided earlier doing this via attributes, I like the strategy, but here What I want is in addition to Module-Specific Resources want to have some global Cross-Module Resources, Which could be used in my modules.

The Given Error :

{"'Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number '10' and line position '18'."}
Inner Exception :
{"Could not load file or assembly 'Resources, Culture=neutral' or one of its dependencies. The system cannot find the file specified.":"Resources, Culture=neutral"}

Nov 5, 2012 at 3:25 PM


After analyzing your sample, I found that in order to avoid the error you mentioned you will have to change the Build Action property of the xaml files where your ResourceDictionary are defined. For example you could try changing these properties to Resource or Page.

Also, you will have to ensure that the Resources.dll file will be copied to the main project folder as currently this is not the case. This behavior can be seen in WPF applications when only defining and using a referenced assembly only in XAML, and a result this assembly won't be loaded if it's not present in the main applications folder.

When following these considerations, I could load the view properly.

Regarding how to share global resources across your different modules, I believe you could achieve this by defining application-wide resources, as once these resources are available in the main application App.xaml file, will be available to be consumed by your different modules.

For more information about this, you could check the following related work items:

I hope you find this handy,

Agustin Adami

Nov 5, 2012 at 8:35 PM

Hi Mr Adami

you were right,

at first the resources were defined as page. and during playing around to find the solution I changed them.

The problem was about not finding the assembly and it was easier than the way I thought I should go with Prism.

Now there are 2 cases to think/talk about, 1st is I think that could be a disability of the .Net that it can't find a referenced assembly !

Isn't it ?

the 2nd part which I wanted to say was that I prefer to make a utility class which could help doing this in code.

Thanks for the help