Wpf 在另一个程序集中查找合并的资源字典时出错

Wpf 在另一个程序集中查找合并的资源字典时出错,wpf,xaml,resourcedictionary,Wpf,Xaml,Resourcedictionary,我真是头撞在墙上了。首先是一些背景。该应用程序是使用WPF的PRISM 4/MVVM应用程序,我的解决方案结构如下: MyCompany.MyProduct (MyCompany.MyProduct.exe) +-- Shell.xaml Shell.xaml.cs app.config (etc) MyCompany.MyProduct.Infrastructure (MyCompany.MyProduct.Infrastructure.dll) +-- Reso

我真是头撞在墙上了。首先是一些背景。该应用程序是使用WPF的PRISM 4/MVVM应用程序,我的解决方案结构如下:

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)
项目参考:

  • MyCompany.MyProduct参考资料 MyCompany.MyProduct.Infrastructure
  • MyCompany.MyProduct.Modules.ModuleA 参考资料 MyCompany.MyProduct.Infrastructure
现在,在Shell.xaml和StuffView.xaml中,我都包含了这样一个合并字典:

<ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary
            Source="pack://application:,,,/MyCompany.MyProduct.Infrastructure;component/Resources/MyApplicationStyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
(叹气)我还注意到xaml编辑器在这一行上显示了两个扭曲的错误:

<ResourceDictionary Source="pack://application:,,,/MyCompany.MyProduct.Infrastructure;component/Resources/MyApplicationStyles.xaml"/>
第二个(更奇怪的)扭曲的错误是

An error occurred while finding the resource dictionary "pack://application:,,,/MyCompany.MyProduct.Infrastrucuture;component/Resources/MyApplicationStyles.xaml".
"Assembly name expected instead of project name."
以下是我尝试过的:

  • 我已经三次检查了项目引用是否存在(我已经删除并重新添加了它们)
  • 我已检查MyCompany.MyProduct.Infrastructure是否成功构建
  • 我已再次检查程序集是否正确(通过AssemblyInfo.cs)
  • 我一次又一次地更改了MyApplicationStyles.xaml上的构建操作(当前设置为“页面”)
  • 我已手动清理解决方案并重新构建
  • 我已经多次重新启动Visual Studio
  • 我牺牲了一只山羊(没关系……他是一只非常不友好的山羊)

我没有主意了,搜索的机会也很少。有什么想法吗?

我遇到了同样的事情,但遇到了不同的情况。一个项目的包uri工作正常,而在同一解决方案的另一个项目中使用的相同uri失败。很好

我让它工作的方法是将有问题的资源作为来自包uri中指定的目标程序集的链接文件添加到失败项目的根。一旦链接文件添加到项目中,包问题就会神奇地出现

步骤(VS2012) 1.右键单击项目并选择“添加”。然后选择“添加现有”。 2.浏览其他项目中的资源文件。 3.突出显示xaml文件。然后通过“添加”按钮选择箭头下拉列表。下拉列表显示“添加为链接”,选择该链接并将其添加到文件中


这样,对该链接文件所做的任何更改都会影响到所有项目,并用pack修复了这个奇怪的问题。

确保编译引用的程序集时针对的是相同版本的.Net framework。

在MyCompany.MyProduct.Infrastructure中仔细检查您的名称空间和程序集名称
"Assembly name expected instead of project name."