C# 无法加载文件或程序集“System.Windows.Interactivity”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13514027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:50:57  来源:igfitidea点击:

Could not load file or assembly 'System.Windows.Interactivity'

c#.netwpfxamlexception

提问by Harry

I just added System.Windows.Interactivity assembly. XamlParse throw me an exception on run time:

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

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”或其依赖项之一。该系统找不到指定的文件。

Google search found only results related to prism - which I do not use.

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

Any idea why does it happen?

知道为什么会发生吗?

采纳答案by Tilak

Just a guess, might be you are not referencing the libraries in the MAIN project.

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

It has happened to me several times.

它发生在我身上好几次。

回答by kmatyaszek

You can find this dll in Blend SDK.

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

Below is link to it:

下面是它的链接:

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

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

回答by Contango

Sometimes, when you add a new library, in introduces a clashing version of System.Windows.Interactivity.dll.

有时,当您添加新库时,会引入一个冲突版本的System.Windows.Interactivity.dll.

This prevents the project from working.

这会阻止项目工作。

To fix, add an Assembly Binding Redirect by editing your app.configto look something like this:

要修复,请通过编辑您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>

Don't worry about changing the PublicKeyToken, that's constant across all versions, as it depends on the name of the .dll, not the version.

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

Ensure that you match the newVersionin your appConfigto the actual version that you end up pointing at:

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

enter image description here

在此处输入图片说明

回答by Amadeusz Wieczorek

Tilak's answer helped me out a big deal, but I also needed to nameat least one element from assembly "i" in the XAML code. When the element is named, Visual Studio correctly hooks up the assembly.

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

Change

改变

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

into

进入

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

This needs to be done to only one element in the entire XAML file.

只需对整个 XAML 文件中的一个元素执行此操作。

回答by Chaitanya Kadamati

You can scan through each of your project for the version of System.Windows.Interactivity eg. 4.0.0.0 or 4.5.0.0. Also, there is a possibility that one of the third party dll that might reference, is depending on System.Windows.Interactivity. So make sure you align the version across your project. This must fix your issue.

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

回答by kyorilys

You could check the project properties -> Build -> Output Path.

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

Go to the output Path director using windows explorer. Then see whether the 'System.Windows.Interactivity.dll' exist in that folder. It might because the CopyLocal flag is false or there is reason The dll file does not generate in the output path folder.

使用 Windows 资源管理器转到输出路径目录。然后查看该文件夹中是否存在“System.Windows.Interactivity.dll”。这可能是因为 CopyLocal 标志为 false 或有原因 dll 文件未在输出路径文件夹中生成。

回答by msr

This was this morning's task. The problem for us was just that the installer moved the location of the DLL. Sometimes it's not a subtle version mismatch: a simple misplacement will cause the same signs. You can use Fuslogvw.exeto help diagnose this. Once you (a) remember to launch the tool with Admin privs and (b) configure the tool to show you binding failures ("Settings"), you'll see log entries like this:

这是今天早上的任务。我们的问题只是安装程序移动了 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. After you put the DLL where it belongs, the log will look like this: 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

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