Rya*_*uer 12 .net c# wpf prism visual-studio
我有C#/ WPF Prism(v4.0)应用程序,它有一个持久的问题,加载/解析Prism库附带的System.Windows.Interactivity dll.我已经连续工作了三天试图调试/解决这个问题.我已经学会了很多关于.Net程序集的解决方案,但到目前为止我的问题没有运气,所以我想我会转而向StackOverflow社区寻求帮助.:)
我有一个模块作为更大的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">
Run Code Online (Sandbox Code Playgroud)
然后我尝试在UserControl的子元素上设置行为,如下所示:
<ListBox Name="myListBox">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SomeCommandOrOther}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
奇怪的是,该项目构建良好,并且当键入关联的代码隐藏文件时,我甚至可以在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.
Run Code Online (Sandbox Code Playgroud)
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"
Run Code Online (Sandbox Code Playgroud)
...正如我从阅读有关汇编解决方案中学到的那样,通常会提出一个问题,解决一个强名称的汇编,而不仅仅是无法在磁盘上找到dll(正如异常类型所暗示的那样).
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.
Run Code Online (Sandbox Code Playgroud)
有趣的是,如果我使用IL反汇编程序(ildasm.exe)查看我的构建项目,则System.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
}
Run Code Online (Sandbox Code Playgroud)
此问题类似于此其他StackOverflow问题中提到的问题:从Prism应用程序引用正确的System.Windows.Interactivity dll.但是,我遵循那里提到的规定的解决方案(即,使用Prism版本的System.Windows.Interactivity),无济于事.只是为了好玩,我还尝试使用Expression Blend 3和4 SDK(当然是单独的)附带的System.Windows.Interactivity dll,但也没有运气.
我在如何加载System.Windows.Interactivity dll以及我如何加载Prism库附带的所有其他dll(它们都位于我的解决方案中的/ lib文件夹中)时,我没有做任何不同的事情.我已经使用Visual Studio 2010中的"添加引用">"浏览"菜单添加它们,并指向磁盘上的所有dll,它们一起放在一个目录中.)
任何关于下一步转向的线索都将非常感激!非常感谢.
Rya*_*uer 32
最后,我找到了答案!
当引用Prism模块中的DLL时,.NET程序集解析机制会在宿主应用程序的/ bin文件夹中查找引用的程序集(即,使用Shell和Bootstrapper的文件夹),而不是在模块的 bin目录中(假设您有在我的解决方案中将模块设置为解决方案中的单独项目.
巧合的是,我的托管应用程序碰巧引用了所有其他Prism DLL,所以当模块引用它们时,它只是在托管应用程序的bin目录中找到它们.但是,我的托管应用程序从未引用System.Windows.Interactivity,因此将其添加到我的模块意味着在托管应用程序/ bin目录中找不到这样的DLL.DLL实际上被复制到模块的/ bin目录,但是汇编解析与Prism应用程序一起工作的一些怪癖意味着应用程序永远不会检查该文件夹中的程序集.
因此,简而言之:Prism应用程序中引用的程序集显然需要驻留在托管应用程序的/ bin文件夹中.
我将看一些使用配置的方法来使这项工作更加干净和智能,但问题的核心至少已被发现.
| 归档时间: |
|
| 查看次数: |
20763 次 |
| 最近记录: |