我有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全部放在一個目錄中。)
任何導致下一個轉向的位置將不勝感激!非常感謝。
是否有在GAC一個版本?你正在建立'任何CPU',並在開發時引用64位,但在運行時32位綁定? FWIW,我沒有線索。 – 2012-03-10 23:08:06
'gacutil -l'確認在GAC中沒有運行System.Windows.Interactivity的版本。爲了回答你的問題,我正在構建「任何CPU」作爲項目屬性中的平臺目標。我的測試機器/操作系統是64位的。但是,我不知道足以在運行時回答有關32位綁定的問題。你能告訴我怎麼檢查嗎?謝謝! – 2012-03-10 23:23:33
嘗試構建爲x86,看看會發生什麼 – 2012-03-10 23:28:20