无法加载文件或程序集'System.Windows.Interactivity'

时间:2012-11-22 13:44:01

标签: c# .net wpf xaml exception

我刚刚添加了System.Windows.Interactivity程序集。 XamlParse在运行时抛出异常:

  

无法加载文件或程序集'System.Windows.Interactivity,   PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。该   系统找不到指定的文件。

谷歌搜索只找到与棱镜有关的结果 - 我不使用。

知道为什么会这样吗?

7 个答案:

答案 0 :(得分:51)

只是一个猜测,可能是你没有引用MAIN项目中的库。

我已经好几次了。

答案 1 :(得分:11)

Tilak的回答帮了我很大的一笔,但我还需要在XAML代码中命名至少一个来自程序集“i”的元素。 命名元素时,Visual Studio会正确连接程序集。

更改

<i:InvokeCommandAction Command="{Binding MyCommand}"/>

进入

<i:InvokeCommandAction Command="{Binding MyCommand}" x:Name="interactivityFix" />

这只需要对整个XAML文件中的一个元素进行。

答案 2 :(得分:8)

有时,当您添加新库时,会引入碰撞版本的System.Windows.Interactivity.dll

这可以防止项目工作。

要修复此问题,请通过修改app.config来添加程序集绑定重定向,如下所示:

<?xml version="1.0"?>
<configuration>
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Windows.Interactivity"
                        publicKeyToken="31bf3856ad364e35"
                        culture="neutral"/>
      <bindingRedirect oldVersion="4.0.0.0"
                       newVersion="4.5.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
<appSettings>
  <add key="TestKey" value="true"/>
</appSettings>

不要担心在所有版本中更改PublicKeyToken,这是常量,因为它取决于.dll的名称,而不是版本。

确保您将newVersion中的appConfig与最终指向的实际版本相匹配:

enter image description here

答案 3 :(得分:4)

你可以在Blend SDK中找到这个dll。

以下是链接:

http://www.microsoft.com/en-us/download/details.aspx?id=10801

答案 4 :(得分:0)

您可以浏览每个项目的System.Windows.Interactivity版本,例如。 4.0.0.0或4.5.0.0。此外,可能引用的第三方dll之一可能取决于System.Windows.Interactivity。因此,请确保在项目中对齐版本。这必须解决您的问题。

答案 5 :(得分:0)

您可以检查项目属性 - &gt;构建 - &gt;输出路径。

使用Windows资源管理器转到输出路径控制器。 然后看看是否有System.Windows.Interactivity.dll&#39;存在于该文件夹中。 可能是因为CopyLocal标志为false或有原因dll文件未在输出路径文件夹中生成。

答案 6 :(得分:0)

这是今天早上的任务。对于我们来说,问题只是安装程序移动了DLL的位置。有时候,这不是一个细微的版本不匹配:简单的放错位置会导致相同的征兆。您可以使用Fuslogvw.exe来帮助诊断。一旦(a)记得使用Admin privs启动该工具,并且(b)配置该工具以显示绑定失败(“设置”),您将看到类似以下的日志条目:

LOG: DisplayName = System.Windows.Interactivity, PublicKeyToken=31bf3856ad364e35 (Partial) WRN: Partial binding information was supplied for an assembly: [ red herring, not a problem for us ] ... LOG: GAC Lookup was unsuccessful [ another red herring: System.Windows.Interactivity.dll is not a core assembly and not registered in the GAC by default ] LOG: Attempting download of new URL file:///C:/Program Files (x86)/<path>/System.Windows.Interactivity.DLL. ... LOG: All probing URLs attempted and failed. 将DLL放在其所属的位置后,日志将如下所示: LOG: GAC Lookup was unsuccessful. LOG: Attempting download of new URL file:///C:/Program Files (x86)/<path>/System.Windows.Interactivity.DLL. LOG: Assembly download was successful. Attempting setup of file: C:\Program Files (x86)\<path>\System.Windows.Interactivity.dll