简体   繁体   English

棱镜组件参考失败:System.Windows.Interactivity

[英]Prism assembly reference failure: System.Windows.Interactivity

I have C#/WPF Prism (v4.0) app that has a persistent problem loading/resolving the System.Windows.Interactivity dll that comes with the Prism library. 我有C#/ WPF Prism(v4.0)应用程序,它有一个持久的问题,加载/解析Prism库附带的System.Windows.Interactivity dll。 I've been working for three days straight trying to debug/solve this problem. 我已经连续工作了三天试图调试/解决这个问题。 I've learned a ton about .Net assembly resolution, but no luck so far on my problem, so I thought I'd turn to the StackOverflow community in a desperate plea for help. 我已经学会了很多关于.Net程序集的解决方案,但到目前为止我的问题没有运气,所以我想我会转而向StackOverflow社区寻求帮助。 :) :)

I have a module running as part of a larger Prism app, which needs to reference System.Windows.Interactivity in order to add behaviors. 我有一个模块作为更大的Prism应用程序的一部分运行,它需要引用System.Windows.Interactivity以添加行为。 Thus I have a XAML user control specifying the namespace as follows: 因此,我有一个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">

And then I am trying to set a behavior on a child element of that UserControl as follows: 然后我尝试在UserControl的子元素上设置行为,如下所示:

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

Oddly, the project builds fine, and when typing in the associate code-behind file and I can even get Intellisense auto-completion for objects in the System.Windows.Interactivity namespace. 奇怪的是,该项目构建良好,并且当键入关联的代码隐藏文件时, 我甚可以在System.Windows.Interactivity命名空间中获取Intellisense自动完成对象。

However, at runtime only , I get a XamlParseException on the above ListBox element. 但是, 仅在运行时 ,我在上面的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. 

The InnerException is of the type System.IO.FileNotFoundException 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"

...which, as I have learned from reading about assembly resolutions, usually suggests a problem resolving a strongly-named assembly rather than merely an inability to find the dll on disk (as the exception type would suggest). ...正如我从阅读有关汇编解决方案中学到的那样,通常会提出一个问题,解决一个强名称的汇编而不仅仅是无法在磁盘上找到dll(正如异常类型所暗示的那样)。

The Fusion log information is as follows, including warning about partial binding for the assembly in question: Fusion日志信息如下,包括有关所涉及程序集的部分绑定的警告:

=== 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.

Interestingly, if I look at my built project using the IL disassembler (ildasm.exe), System.Windows.Interactivity is not listed in the manifest as one of the referenced assemblies, though the other referenced Prism dlls show up there just fine. 有趣的是,如果我使用IL反汇编程序(ildasm.exe)查看我的构建项目,则System.Windows.Interactivity未在清单中列为引用程序集之一,尽管其他引用的Prism dll在那里显示就好了。 For example: 例如:

.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
}

This problem is similar to the one mentioned in this other StackOverflow question: Referencing the correct System.Windows.Interactivity dll from Prism application . 此问题类似于此其他StackOverflow问题中提到的问题: 从Prism应用程序引用正确的System.Windows.Interactivity dll However, I am following the prescribed solution mentioned there (ie, using the Prism version of System.Windows.Interactivity), to no avail. 但是,我遵循那里提到的规定的解决方案(即,使用Prism版本的System.Windows.Interactivity),无济于事。 Just for fun, I have also tried using the System.Windows.Interactivity dlls that come with both the Expression Blend 3 and 4 SDKs (separately of course), but no luck with those either. 只是为了好玩,我还尝试使用Expression Blend 3和4 SDK(当然是单独的)附带的System.Windows.Interactivity dll,但也没有运气。

I'm not doing anything differently in how I've loaded the System.Windows.Interactivity dll from how I've loaded all the other dlls that come with the Prism library (they all reside in a /lib folder in my solution, and I've added them using the "Add reference" > "Browse" menu in Visual Studio 2010 and pointing to those dlls on disk sitting all together in one directory.) 我在如何加载System.Windows.Interactivity dll以及我如何加载Prism库附带的所有其他dll(它们都位于我的解决方案中的/ lib文件夹中)时,我没有做任何不同的事情。我已经使用Visual Studio 2010中的“添加引用”>“浏览”菜单添加它们,并指向磁盘上的所有dll,它们一起放在一个目录中。)

Any leads on where to turn next would be most appreciated! 任何关于下一步转向的线索都将非常感激! Many thanks. 非常感谢。

At last, I found the answer! 最后,我找到了答案!

When DLLs in Prism modules are referenced, the .NET assembly resolution mechanism looks for the referenced assemblies in the /bin folder of the hosting application (ie, the one with the Shell and Bootstrapper) rather than in the module's bin directory (assuming you have set up your modules as separate projects in the solution, as I have). 当引用Prism模块中的DLL时,.NET程序集解析机制会在宿主应用程序的/ bin文件夹中查找引用的程序集(即,使用Shell和Bootstrapper的文件夹),而不是在模块的 bin目录中(假设您有在我的解决方案中将模块设置为解决方案中的单独项目。

By coincidence, my hosting application happened to reference all the other Prism DLLs, so when the modules referenced those, it just found them in the hosting application's bin directory. 巧合的是,我的托管应用程序碰巧引用了所有其他Prism DLL,所以当模块引用它们时,它只是在托管应用程序的bin目录中找到它们。 However, my hosting application never referenced System.Windows.Interactivity, so adding it just to my module meant there was no such DLL to be found in the hosting applications /bin directory. 但是,我的托管应用程序从未引用System.Windows.Interactivity,因此将其添加到我的模块意味着在托管应用程序/ bin目录中找不到这样的DLL。 The DLL is in fact being copied to the /bin directory of the module, but some quirk of the way assembly resolution works with Prism applications means that the app never checks for assemblies in that folder. DLL实际上被复制到模块的/ bin目录,但是汇编解析与Prism应用程序一起工作的一些怪癖意味着应用程序永远不会检查该文件夹中的程序集。

So, in short: referenced assemblies in Prism applications apparently need to reside in the /bin folder of the hosting application. 因此,简而言之:Prism应用程序中引用的程序集显然需要驻留在托管应用程序的/ bin文件夹中。

I'm going to look at some means of using configuration to make this work more cleanly and intelligently, but the core of the problem has at least been uncovered. 我将看一些使用配置的方法来使这项工作更加干净和智能,但问题的核心至少已被发现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM