Could not load file or assembly 'System.Window

2019-01-12 02:44发布

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

Could not load file or assembly 'System.Windows.Interactivity, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

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

Any idea why does it happen?

7条回答
唯我独甜
2楼-- · 2019-01-12 02:51

You can find this dll in Blend SDK.

Below is link to it:

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

查看更多
ら.Afraid
3楼-- · 2019-01-12 02:52

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

It has happened to me several times.

查看更多
可以哭但决不认输i
4楼-- · 2019-01-12 02:52

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.

查看更多
Summer. ? 凉城
5楼-- · 2019-01-12 02:56

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

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.

查看更多
疯言疯语
6楼-- · 2019-01-12 02:57

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.

查看更多
何必那么认真
7楼-- · 2019-01-12 03:04

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

This prevents the project from working.

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

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

Ensure that you match the newVersion in your appConfig to the actual version that you end up pointing at:

enter image description here

查看更多
登录 后发表回答