2011-06-07 45 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

相關問題