2011-06-07 46 views
4

我真的在这里撞墙。首先,一些背景。该应用程序是使用WPF棱镜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> 

在这两种情况下,但是,我正在头先入以下错误:

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

(叹气)我也注意到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构建成功
  • 我已仔细检查程序集是否正确T(通过的AssemblyInfo.cs)
  • 我已经改变了对MyApplicationStyles.xaml时间生成操作,并再次(它目前设置为“页”)
  • 我手动清洗液和重建
  • 我VE重新启动Visual Studio中的几次
  • 我已经牺牲了山羊(也没关系......他是一个非常不友好的山羊)

我的想法和搜索被转动起来非常小。有任何想法吗?

+0

在MyCompany.MyProduct.Infrastructure中仔细检查您的名称空间和程序集名称 – 2012-07-11 05:29:22

回答

0

我遇到了不同的麻烦。一个项目的包uri工作得很好,而同一个uri在另一个项目中使用的解决方案失败。太好了!

我得到它的工作方式是将问题中的资源添加到失败项目的根目录作为pack uri中指定的目标程序集的链接文件。一旦链接文件被添加到项目中,包装问题神奇地消失。

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

通过这种方式,对这个链接文件所做的任何更改都可以通向所有项目并修复这个奇怪的问题。

1

确保引用的程序集是针对相同版本的.Net框架进行编译的。

+0

这解决了我的问题! – FrankyB 2014-03-06 15:32:50

相关问题