2012-03-10 72 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