Visual Studio 扩展无法找到所需的程序集。

7
我为 Visual Studio 2013 编写了一个扩展程序。由于该ComboBox bug的存在,我不得不将System.Windows.Interactivity加入到我的项目中。要添加更多细节,请看下面:

  1. <Project>使用其他解决方案组件,如<Project>.Editor,其中包含实际编辑器。
  2. <Project>.Editor 引用 System.Windows.Interactivity
  3. <Project>也引用了 System.Windows.Interactivity, 我实际上是使用 nuget 来加载 Expression.Blend.Sdk 包 (它与 WPF 4.5 兼容)

效果: 当包含所述的 ComboBox 的编辑器部分显示时,我立即得到一个异常:

一个类型为'System.Windows.Markup.XamlParseException'的异常已在 PresentationFramework.dll 中发生。

更多信息: 找不到文件或程序集“System.Windows.Interactivity,PublicKeyToken = 31bf3856ad364e35”或其某个依赖项。系统找不到指定的文件。

我正在实验性的实例中运行此扩展程序,并且该文件夹:

C:\Users\<user>\AppData\Local\Microsoft\VisualStudio\12.0Exp\Extensions\<Company>\<Extension>\1.0

包含 System.Windows.Interactivity.dll,但由于某些原因,它似乎无法被 IDE 看到。

更奇怪的是,我正在使用其他附加包,例如 IronPython,它们从未给我带来过这样的麻烦。

我该如何解决这个问题?


编辑: 回应评论

实际上,InnerException 包含一个名为 FusionLog 的字段,其中包含以下内容:

=== Pre-bind state information ===
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:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\<user>\AppData\Local\Temp\devE4FC.tmp
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:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/System.Windows.Interactivity/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PublicAssemblies/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PublicAssemblies/System.Windows.Interactivity/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/System.Windows.Interactivity/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/System.Windows.Interactivity/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/CommonExtensions/Platform/Debugger/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/CommonExtensions/Platform/Debugger/System.Windows.Interactivity/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/DataCollectors/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/DataCollectors/System.Windows.Interactivity/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/DataCollectors/x86/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/DataCollectors/x86/System.Windows.Interactivity/System.Windows.Interactivity.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/System.Windows.Interactivity/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PublicAssemblies/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PublicAssemblies/System.Windows.Interactivity/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/System.Windows.Interactivity/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/System.Windows.Interactivity/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/CommonExtensions/Platform/Debugger/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/CommonExtensions/Platform/Debugger/System.Windows.Interactivity/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/DataCollectors/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/DataCollectors/System.Windows.Interactivity/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/DataCollectors/x86/System.Windows.Interactivity.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/DataCollectors/x86/System.Windows.Interactivity/System.Windows.Interactivity.EXE.

但还有更多。我使用 ProcMon 检查,发现 Visual Studio 在寻找该 DLL 的位置最终是:
08:46:46,7508050    devenv.exe  7544    CreateFile  C:\Users\<user>\AppData\Local\Microsoft\VisualStudio\12.0Exp\Extensions\<Company>\<Extension>\1.0\Lib\System.Windows.Interactivity  NAME NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
08:46:46,7509231    devenv.exe  7544    CreateFile  C:\Users\<user>\AppData\Local\Microsoft\VisualStudio\12.0Exp\Extensions\<Company>\<Extension>\1.0\Lib\System.Windows.Interactivity.EXE  NAME NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
08:46:46,7510379    devenv.exe  7544    CreateFile  C:\Users\<user>\AppData\Local\Microsoft\VisualStudio\12.0Exp\Extensions\<Company>\<Extension>\1.0\Lib\System.Windows.Interactivity.DLL  NAME NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a

Lib文件夹包含一些我正在使用的Python模块(用于脚本编写,因为我正在使用IronPython)。具有讽刺意味的是,程序集位于

C:\Users\<user>\AppData\Local\Microsoft\VisualStudio\12.0Exp\Extensions\<Company>\<Extension>\1.0\

文件夹(不包括Lib文件夹)。但是,尽管请求程序集也驻留在那里,Visual Studio在搜索中省略了它,尽管它是最自然的搜索位置。


尝试将该dll复制到日志中提到的任何路径中。我个人会将该程序集放在...\PublicAssemblies中。 - rene
1
@rene 当然,我之前试过,并且它可以工作,但是我不能要求插件的用户手动复制程序集到某个地方:) 问题是,我如何告诉Visual Studio在哪里查找程序集?为什么IronPython可以无问题加载而System.Windows.Interactivity却不行呢? - Spook
当然,至少我们已经确认这是一个绑定问题而不是其他模糊的问题... - rene
1
@rene 我对IronPythonSystem.Windows.Interactivity有一个可行的理论。 IronPython是从我的插件代码加载的,而后者是从XAML加载的,因此负责尝试加载System.Windows.Interactivity的程序集是PresentationFramework.dll。该程序集反过来在应用程序上下文中工作,在这种情况下是Visual Studio,因此它使用其文件夹寻找程序集并显然失败。 - Spook
@rene 我的想法是在解析 XAML 文件之前从代码中强制加载 System.Windows.Interactivity,这样 PresentationFramework.dll 就不会尝试查找它。我正在准备这样的代码过程中。 - Spook
显示剩余2条评论
3个回答

7

这是解决问题的一个变通方法。虽然我不喜欢它,但它确实有效 :)

解决方案是强制从源代码加载程序集,这样PresentationFramework在解析XAML文件时就不必寻找它了。例如:

private static void LoadSystemWindowsInteractivity()
{
    // HACK: Force load System.Windows.Interactivity.dll from plugin's 
    // directory
    typeof(System.Windows.Interactivity.Behavior).ToString();
}

static MyEditorFactory()
{
    LoadSystemWindowsInteractivity();
}

2
我有同样的问题。以下解决方案适用于我。
1. 创建一个名为"MyDef.pkgdef"的文本文件。 2. 更改内容为:
[$RootKey$\BindingPaths{some_guid}] "$PackageFolder$"=""
3. 在.vsixmanifest文件中添加一个资产 4. 确保引用的dll必须签名,并且“Copy Local”属性必须为true。

0

1
我目前正在使用 Microsoft.Xaml.Behaviors.Wpf,但仍然遇到了这个确切的问题。一旦我按照此评论中建议的做法去做,问题就解决了。"另一个可能有帮助的想法:至少必须命名来自程序集“i”的一个元素,以便VS正确地连接程序集。<i:InvokeCommandAction Command="{Binding MyCommand}" x:Name="interactivityFix" /> – Amadeusz Wieczorek Jun 18 '14 at 16:44" - Yann Duran

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接