开发者

Error finding merged resource dictionary in another assembly

开发者 https://www.devze.com 2023-03-11 06:08 出处:网络
I\'m really beating my head against the wall here. First, some background. The app is a PRISM 4/MVVM app using WPF and my solution is structured as follows:

I'm really beating my head against the wall here. First, some background. The app is a PRISM 4/MVVM app 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)

Project References:

  • MyCompany.MyProduct references MyCompany.MyProduct.Infrastructure
  • MyCompany.MyProduct.Modules.ModuleA references MyCompany.MyProduct.Infrastructure

Now, In both Shell.xaml and StuffView.xaml, I include a merged 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'm running head-first into 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 notice that the xaml editor is showing me two squiggly errors on this line:

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

The first squiggly error is...

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

The second (an more curious) squiggly error is...

"Assembly name expected instead of project name."

So here's what I've tried:

  • I've triple-checked that the project references exist (and I've removed and re-added them)
  • I've checked that MyCompany.MyProduct.Infrastructure builds successfully
  • I've double-checked that the assembly is correct (via AssemblyInfo.cs)
  • I've changed the Build Action on MyApplicationStyles.xaml time and again (it's currently set to "Page")
  • I've manually cleaned the solution and rebuilt
  • I've re-started Visual Studio a couple of times
  • I've sacrificed a goat (it's okay... he was a really unfriendly goat)

I'm out of ideas and searching is turning up very little. Any ideas?


Make sure the referenced assembly was compiled for targeting the same version of .Net framework.


I ran into the same thing with a different twist. One project's pack uri worked fine, while the same uri used in another project in the same solution failed. Nice!

The way I got it to work was to add the resource in question to the root of the failure project as a linked file from the target assembly specified in the pack uri. Once the linked file was added to the project, the pack issue magically dissappeared.

Steps (VS2012) 1. Right Click on the project and select "Add". Then Select "add existing". 2. Browse for the resource file in the other project. 3. Highlight the xaml file. Then select the arrow drop by the "add" button. The drop down presents "add as link", select that and add it to the file.

That way any changes done to this linked file makes its way to all projects and fixes this bizarre issue with pack.

0

精彩评论

暂无评论...
验证码 换一张
取 消