views:

105

answers:

1

In Visual Studio when I linked a file from one project to the next, I get the following error when an attempt is made to load the linked resource. This only happens when the linked file is within a folder(s).

Error:

Message="'pack://application:,,,/projectName ;component/ResourceDictionary .xaml' value cannot be assigned to property 'Source' of object 'System.Windows.SharedResourceDictionary'.

Example:

Project1.Resources
           |
           |--> MergedResourceDictionary.xaml
           |--> ProjectResourceDictionary.xaml
           |--> Folder
                     |
                     |--> SharedResourceDictionary.xaml           


Project2.Resources
           |
           |--> MergedResourceDictionary.xaml
           |--> ProjectResourceDictionary.xaml
           |--> Folder
                     |
                     |--> SharedResourceDictionary.xaml  **LINKED**

If in the MergedResourceDictionary.xaml we merged these dictionaries, then the "SharedResourceDictionary.xaml in Project2 will not be found. However, if the SharedResourceDictionary.xaml is linked at the root of the project then the resource is found at runtime.

**NOTE: In the "obj/debug" of project2, all linked resources are at the root directory, whereas in project1 resources remain within the folder structure assigned in the project.

Steps to recreate This happens at runtime. Steps are as follows (using files listed in original post).

1) Create SharedResourceDictionary in Project1, within "Folder" 2) Create "Folder" in Project2, then add "as link" SharedResourceDictionary within the folder 3) Build and run app 4) App will not be able to find the SharedResourceDictionary.xaml, due to it residing within the Folder. Removing the file from the folder structure will work fine as a linked file.

I appreciate any assistance,

Chris

A: 

I spent sometime working with Microsoft support on this problem. It is a bug with MsBuild and doubtful to be something they fix in the future.

I have found a workaround for anyone that is interested:

Create a PostBuild event that runs LocBaml and creates the folder structure that you require and places the files in the correct folder.

Hope this helps.

Chris Nicol