2012-03-10 62 views
11

我有C#/ WPF Prism(v4.0)應用程序有加載/解決Prism庫附帶的System.Windows.Interactivity dll的持久性問題。我一直在嘗試調試/解決這個問題,一直工作三天。我已經學會了大量的.Net程序集解決方案,但在我的問題上至今沒有運氣,所以我想我會轉向StackOverflow社區,以絕望的呼籲請求幫助。 :)棱鏡程序集引用失敗:System.Windows.Interactivity

我有一個模塊作爲更大的Prism應用程序的一部分運行,它需要引用System.Windows.Interactivity以添加行爲。因此,我有一個XAML用戶控制指定的命名空間如下:

<UserControl x:Class="MyApp.Modules.SourcesModule.myView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"> 

然後我想設置一個行爲用戶控件的子元素如下:

<ListBox Name="myListBox"> 
    <i:Interaction.Triggers> 
     <i:EventTrigger EventName="SelectionChanged"> 
      <i:InvokeCommandAction Command="{Binding SomeCommandOrOther}"/> 
     </i:EventTrigger> 
    </i:Interaction.Triggers> 
</ListBox> 

奇怪的是,該項目生成的很好,並且在關聯代碼隱藏文件和中輸入時,我甚至可以爲System.Windows.Interactivity命名空間中的對象獲取Intellisense自動完成

但是,在運行時只有,我在上面的ListBox元素上得到一個XamlParseException。

Could not load file or assembly 'System.Windows.Interactivity, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 

的的InnerException是類型System.IO.FileNotFoundException

"Could not load file or assembly 'System.Windows.Interactivity, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.":"System.Windows.Interactivity, PublicKeyToken=31bf3856ad364e35" 

...這,因爲我從閱讀有關大會決議瞭解到,通常表明解決強命名程序集的問題而不僅僅是無法在磁盤上找到dll(因爲異常類型會提示)。

融合日誌信息如下,包括問題的警告有關部分裝訂的裝配:

=== Pre-bind state information === 
LOG: User = aricebo-array\me 
LOG: DisplayName = System.Windows.Interactivity, PublicKeyToken=31bf3856ad364e35 
(Partial) 
WRN: Partial binding information was supplied for an assembly: 
WRN: Assembly Name: System.Windows.Interactivity, PublicKeyToken=31bf3856ad364e35 | Domain ID: 1 
WRN: A partial bind occurs when only part of the assembly display name is provided. 
WRN: This might result in the binder loading an incorrect assembly. 
WRN: It is recommended to provide a fully specified textual identity for the assembly, 
WRN: that consists of the simple name, version, culture, and public key token. 
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue. 
LOG: Appbase = file:///C:/Users/me/Documents/Development Projects/Desktop apps/Prism/MyApp/Src/MyApp/bin/Debug/ 
LOG: Initial PrivatePath = NULL 
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35. 
=== 
LOG: This bind starts in default load context. 
LOG: No application configuration file found. 
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. 
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). 
LOG: Attempting download of new URL file:///C:/Users/me/Documents/Development Projects/Desktop apps/Prism/MyApp/Src/MyApp/bin/Debug/System.Windows.Interactivity.DLL. 
LOG: Attempting download of new URL file:///C:/Users/me/Documents/Development Projects/Desktop apps/Prism/MyApp/Src/MyApp/bin/Debug/System.Windows.Interactivity/System.Windows.Interactivity.DLL. 
LOG: Attempting download of new URL file:///C:/Users/me/Documents/Development Projects/Desktop apps/Prism/MyApp/Src/MyApp/bin/Debug/System.Windows.Interactivity.EXE. 
LOG: Attempting download of new URL file:///C:/Users/me/Documents/Development Projects/Desktop apps/Prism/MyApp/Src/MyApp/bin/Debug/System.Windows.Interactivity/System.Windows.Interactivity.EXE. 

有趣的是,如果我查看使用IL反彙編程序(Ildasm.exe),系統建立我的項目.Windows.Interactivity沒有在清單中作爲引用的程序集之一列出,但其他引用的Prism dll顯示在那裏很好。例如:

.assembly extern Microsoft.Practices.Prism 
{ 
    .publickeytoken = (31 BF 38 56 AD 36 4E 35)       // 1.8V.6N5 
    .ver 4:0:0:0 
} 
.assembly extern Microsoft.Practices.Unity 
{ 
    .publickeytoken = (31 BF 38 56 AD 36 4E 35)       // 1.8V.6N5 
    .ver 2:0:414:0 
} 

這個問題類似於此的其他StackOverflow的問題中提到的一個:Referencing the correct System.Windows.Interactivity dll from Prism application。但是,我遵循上面提到的規定解決方案(即使用System.Windows.Interactivity的Prism版本),無濟於事。爲了好玩,我也嘗試過使用Expression Blend 3和4 SDK(當然要單獨使用)提供的System.Windows.Interactivity dll,但沒有運氣。

我沒有做任何不同的事情,在我如何加載System.Windows.Interactivity DLL從我如何加載所有其他與棱鏡庫附帶的DLL(它們都駐留在/ lib文件夾中我的解決方案,我已經使用Visual Studio 2010中的「添加引用」>「瀏覽」菜單添加了它們,並指向磁盤上的這些DLL全部放在一個目錄中。)

任何導致下一個轉向的位置將不勝感激!非常感謝。

+0

是否有在GAC一個版本?你正在建立'任何CPU',並在開發時引用64位,但在運行時32位綁定? FWIW,我沒有線索。 – 2012-03-10 23:08:06

+0

'gacutil -l'確認在GAC中沒有運行System.Windows.Interactivity的版本。爲了回答你的問題,我正在構建「任何CPU」作爲項目屬性中的平臺目標。我的測試機器/操作系統是64位的。但是,我不知道足以在運行時回答有關32位綁定的問題。你能告訴我怎麼檢查嗎?謝謝! – 2012-03-10 23:23:33

+0

嘗試構建爲x86,看看會發生什麼 – 2012-03-10 23:28:20

回答

32

最後,我找到了答案!

當引用Prism模塊中的DLL時,.NET程序集解決機制查找在託管應用程序的/ bin文件夾中引用的程序集(即一個與殼牌和引導程序),而不是在模塊 bin目錄中(假設你已經設置了模塊作爲單獨的像我一樣,解決方案中的項目)。

巧合的是,我的託管應用程序發生引用所有其他棱鏡的DLL,所以當模塊引用的那些,它只是發現他們在宿主應用程序的bin目錄。但是,我的託管應用程序從未引用System.Windows.Interactivity,因此僅將它添加到我的模塊中意味着在託管applications/bin目錄中找不到此類DLL。實際上DLL被複制到模塊的/ bin目錄中,但是組裝解決方案的一些怪癖與Prism應用程序一起工作意味着應用程序從不檢查該文件夾中的程序集。

因此,簡而言之:在棱鏡應用程序引用的程序顯然需要駐留在託管應用程序的/ bin文件夾。

我要去看看使用的配置,以使這項工作更清潔,智能的一些手段,但問題的核心已經至少被發現。

+0

「添加模塊嚮應用程序」的段[本文](http://www.codeproject.com/Articles/165376/A-Prism-4-Application-Checklist)提供了管理方式組件的一些見解和提示在Prism應用程序中編織在一起(即模塊化的怪癖)。 – 2012-03-11 15:39:58

+0

我使用了Expression Blend SDK的dll,並將它移到了常見的Libs文件夾中。我的模塊之一是使用DLL,因爲你提到添加引用殼牌應用程序工作。 – mehul9595 2013-06-08 04:51:05

+0

它就像一個魅力!:) – StepUp 2015-10-20 05:59:13