23

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?

Tilak
  • 30,108
  • 19
  • 83
  • 131
Harry
  • 1,686
  • 2
  • 15
  • 21
  • It's part of [Expression Studio](http://msdn.microsoft.com/en-us/library/system.windows.interactivity(v=expression.40).aspx) – ChrisF Nov 22 '12 at 13:47
  • 1
    So? Should I install something? – Harry Nov 22 '12 at 13:47
  • Here's the MSDN page - http://msdn.microsoft.com/en-us/library/system.windows.interactivity.invokecommandaction(v=expression.40).aspx – ChrisF Nov 22 '12 at 13:48
  • I did not understand how it helps me. I know how to use the class, it compiled fine, crash on run time. – Harry Nov 22 '12 at 13:51
  • 3
    Just a guess, might be you are not referencing the libraries in the MAIN project? – Tilak Nov 22 '12 at 14:08
  • @Tilak, Thanks, this is the solution. Write it as answer so I can accept it. – Harry Nov 25 '12 at 06:31
  • 2
    Another thought that might help some: At least one element from assembly "i" must be named, so that VS correctly hooks up the assembly. – Amadeusz Wieczorek Jun 18 '14 at 16:44
  • 1
    @AmadeuszWieczorek : please add your solution as answer, it helped me a lot. Thanks. – Sivasubramanian Aug 10 '15 at 09:45
  • I actually found the solution for this [here](https://stackoverflow.com/q/29362125/95573) which was different than any of the answer for this question. – SwDevMan81 May 16 '18 at 14:25

7 Answers7

61

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

It has happened to me several times.

Tilak
  • 30,108
  • 19
  • 83
  • 131
20

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.

Amadeusz Wieczorek
  • 3,139
  • 2
  • 28
  • 32
  • 2
    My Window is called from a DLL inside a non-WPF application. This seemed to do the trick, thanks! – Kolky May 16 '16 at 12:14
  • 1
    All I had to do with my was just add a name per this answer. Definitely instills confidence in me with regards to the tooling... – curob Feb 02 '17 at 22:46
  • I'm in the same context as @Kolky and I wouldn't have believed that would do the trick. Yet it does... – Didier Ghys Apr 12 '18 at 09:27
  • 1
    I had this happen with my VS extension [Start Page+](http://luminous-software.solutions/start-page-plus). The XAML is in a `ToolWindow`, in a separate project from the VSIX project. Following Tilak's advise didn't help in my situation, but following Amadeusz's did, but I only needed the naming hack, not both answers together. – Yann Duran May 09 '20 at 08:52
  • 1
    This name detail was the only thing I needed to do. If you are having this problem, first try the name trick by itself. Do not add any additional references before confirming they are actually necessary, because they may not be. – Daniel Dec 20 '21 at 17:08
10

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>
</configuration>

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

riQQ
  • 9,878
  • 7
  • 49
  • 66
Contango
  • 76,540
  • 58
  • 260
  • 305
4

You can find this dll in Blend SDK.

Below is link to it:

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

kmatyaszek
  • 19,016
  • 9
  • 60
  • 65
1

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.

  • Rather than 'This must fix your issue', try and say something less forceful. If it doesn't fix it (And since the post is 3 years old, it probably already has a fix), then your answer will be downvoted a lot. – David Nov 18 '16 at 09:52
1

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.exe to 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:

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

msr
  • 336
  • 3
  • 7
0

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.

kyorilys
  • 822
  • 13
  • 27