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

2023-09-02 10:38:37 作者:°夏日╮ ﹏secret°

我有C#/ WPF棱镜(V4.0)应用程序,有一个长期存在的问题装载/解决随附棱镜库System.Windows.Interactivity DLL。我已经工作了三天试图调试/解决这个问题。我已经学到了很多关于.NET程序集的分辨率,但至今没有运气上我的问题,所以我想我会谈谈的StackOverflow社区在绝望请求帮助。 :)

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. 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. :)

我作为一个更大的棱镜的应用程序,这需要引用System.Windows.Interactivity以添加行为,部分模块运行。因此,我有一个XAML用户控件指定命名空间,如下所示:

I have a module running as part of a larger Prism app, which needs to reference System.Windows.Interactivity in order to add behaviors. Thus I have a XAML user control specifying the namespace as follows:

<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:

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

奇怪的是,该项目构建的罚款,并在该联营code-隐藏文件和打字的我甚至可以智能感知自动完成的在System.Windows.Interactivity命名空间中的物体时。

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.

然而,的在运行时仅的,我得到了上面的列表框元素上XamlParseException。

However, at runtime only, I get a XamlParseException on the above ListBox element.

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

The InnerException is of the type 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(因为异常的类型所暗示的)。

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

融合日志信息如下,包括警告有关部分的结合有问题的组件:

The Fusion log information is as follows, including warning about partial binding for the assembly in question:

=== Pre-bind state information ===
LOG: User = aricebo-arrayme
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:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.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反汇编,System.Windows.Interactivity没有在清单中列出作为参考的组件之一,但另一个引用棱镜的dll显示那里只是程序(Ildasm.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. 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
}

这个问题类似于在这个其他的StackOverflow问题提到了一句:Referencing正确的System.Windows.Interactivity DLL从棱镜应用。不过,我下面有提到的prescribed溶液(即使用棱镜版System.Windows.Interactivity的),都无济于事。只是为了好玩,我也尝试过使用System.Windows.Interactivity的DLL附带两个防爆pression混合3和4的SDK(单独的课程),但没有运气与那些无论是。

This problem is similar to the one mentioned in this other StackOverflow question: Referencing the correct System.Windows.Interactivity dll from Prism application. However, I am following the prescribed solution mentioned there (i.e., using the Prism version of System.Windows.Interactivity), to no avail. 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.

我不如何我已经加载的我是如何加载的所有附带棱镜库中的其他DLL的System.Windows.Interactivity DLL做什么不同(他们都住在一个/ lib文件夹我的解决方案,我已经添加使用Visual Studio 2010中的添加引用>浏览菜单,指向这些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.)

这是在哪里拐弯下一任何线索将是非常美联社preciated!非常感谢。

Any leads on where to turn next would be most appreciated! Many thanks.

推荐答案

最后,我找到了答案!

当在棱镜模块的DLL被引用,.NET程序集解析机制查找引用的程序集在主机的应用程序的/ bin文件夹(例如,一个与壳牌和引导程序),而比在模块的bin目录中(假设你已经设置了模块作为解决方案不同的项目,因为我有)。

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 (i.e., 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).

巧合的是,我的托管应用程序发生在引用其他所有棱镜的DLL,所以当模块引用的那些,它只是发现他们在宿主应用程序的bin目录。然而,我的托管应用程序不会被引用System.Windows.Interactivity,所以将它只是给我的模块意味着没有这样的DLL中托管的应用程序/ bin目录中找到。该DLL实际上是在被复制到模块的/ 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. 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. 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.

因此​​,简而言之:引用的程序集的棱镜应用显然需要驻留在宿主应用程序的/ bin文件夹

So, in short: referenced assemblies in Prism applications apparently need to reside in the /bin folder of the hosting application.

我要看看使用的配置,使这项工作更加干净,聪明的一些手段,但问题的核心已经至少被发现。

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.