Error finding a merged resource dictionary in another assembly

I really hit my head against the wall here. Firstly, some background. The application is a PRISM 4 / MVVM application using WPF, and my solution is structured as follows:

MyCompany.MyProduct (MyCompany.MyProduct.exe) +-- Shell.xaml Shell.xaml.cs app.config (etc) MyCompany.MyProduct.Infrastructure (MyCompany.MyProduct.Infrastructure.dll) +-- Resources | +-- MyApplicationStyles.xaml | SuperCoolImage.png | (etc) +-- BaseClasses +-- ViewModelBase.cs (etc) MyCompany.MyProduct.Modules.ModuleA (MyCompany.MyProduct.Modules.ModuleA.dll) +-- ViewModels | +-- StuffViewModel.cs | (etc) +-- Views +-- StuffView.xaml StuffView.xaml.cs (etc) 

Links to projects:

  • Links to MyCompany.MyProduct MyCompany.MyProduct.Infrastructure
  • MyCompany.MyProduct.Modules.ModuleA Recommendations MyCompany.MyProduct.Infrastructure

Now, in both Shell.xaml and StuffView.xaml, I include a federated dictionary as such:

 <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/MyCompany.MyProduct.Infrastructure;component/Resources/MyApplicationStyles.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> 

In both cases, however, I run head-first with the following error:

 Could not load file or assembly 'MyCompany.MyProduct.Infrastructure, Culture=neutral' or one of its dependencies. The system cannot find the file specified. 

(sigh) I also noticed that the xaml editor shows me two squiggly errors on this line:

 <ResourceDictionary Source="pack://application:,,,/MyCompany.MyProduct.Infrastructure;component/Resources/MyApplicationStyles.xaml"/> 

First squiggly error ...

 An error occurred while finding the resource dictionary "pack://application:,,,/MyCompany.MyProduct.Infrastrucuture;component/Resources/MyApplicationStyles.xaml". 

The second (more curious) short mistake ...

 "Assembly name expected instead of project name." 

So here is what I tried:

  • I checked three times that the project links exist (and I deleted and added them again)
  • I checked that MyCompany.MyProduct.Infrastructure works successfully
  • I double checked that the assembly is correct (via AssemblyInfo.cs)
  • I changed the build action to MyApplicationStyles.xaml again and again (it is currently set to "Page")
  • I manually cleared the solution and rebuilt
  • I restarted Visual Studio several times
  • I sacrificed a goat (all right ... he was a very unfriendly goat)

I have no ideas, and the search is very few. Any ideas?

+4
wpf xaml resourcedictionary
source share
2 answers

Make sure the assembly link has been compiled to target the same version of the .Net framework.

+1
source share

I ran into the same other turn. One uri project package worked fine, but the same uri that was used in another project in the same solution failed. Nice!

The way I worked was to add the appropriate resource to the root of the crash project as a linked file from the target assembly specified in the uri package. As soon as the linked file was added to the project, the problem with the package magically disappeared.

Steps (VS2012) 1. Right-click on the project and select Add. Then select "Add Existing". 2. Locate the resource file in another project. 3. Highlight the xaml file. Then select the down arrow with the Add button. The drop-down list shows "Add as link", select it and add it to the file.

Thus, any changes made in this linked file make their way to all projects and fix this strange package issue.

0
source share

All Articles