title: How to resolve "Could not load file or assembly 'Microsoft.Practices.Unity" error?
body: <p>I've run into an error with a test WPF application that I'm using to learn Prism. The error log is below, but the gist of it is that it can't seem to find Microsoft.Practices.Unity version 3.5.1.0. From my understanding this can mean two things: either it can't find any version of Unity, or it's finding the wrong version number of Unity.</p>
  
  <p>To rule out the first option (at least I believe this rules it out) I double checked that the dll is installed in the projects that need it and in the bin folder; there is only one copy of Unity within each project and the bin folder. It is installed, but per the properties description it says that the version is 3.5.0.0. Per the Object Browser it says the dll is in a folder titled "Unity.3.5.1404.0". Note that the dll was installed using NuGet, and the two groups of packages I installed are called "Prism" and "Prism.UnityExtensions." It's the second one that the Unity dll is in.</p>
  
  <p>What's interesting is that I actually started a new tutorial project to see if it'd fix the issue, and copied over some pieces of the projects from the original one. I was able to compile and run it the first time, but then I took out the section of code below from the App.config file just to see what would happen (dumb mistake...) and started getting the same error. This is even after I added it back to the App.config file. Note that the code below was in the App.config file when I created the project; it's not something I personally added later.</p>
  
  <p>Is there somewhere else I should look for rogue Unity dlls that might be causing issues? Is there something I need to add or remove so that the current Unity dll will work?</p>
  
  <hr>
  
  <p>Code where error is happening (on bootstrapper.Run; this is in App.xaml.cs):</p>
  
  <pre><code>protected override void OnStartup(StartupEventArgs e)
      {
          base.OnStartup(e);
  
          Bootstrapper bootstrapper = new Bootstrapper();
          bootstrapper.Run();
      }
  </code></pre>
  
  <hr>
  
  <p>Code:</p>
  
  <pre><code>  &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
    &lt;/startup&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Practices.Prism.SharedInterfaces" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.5.1.0" newVersion="3.5.1.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
  </code></pre>
  
  <hr>
  
  <p>Error:</p>
  
  <blockquote>
    <p>System.IO.FileLoadException was unhandled
      HResult=-2146234304
      Message=Could not load file or assembly 'Microsoft.Practices.Unity, Version=3.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
      Source=Microsoft.Practices.Prism.UnityExtensions
      FileName=Microsoft.Practices.Unity, Version=3.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
      FusionLog=""
      StackTrace:
           at Microsoft.Practices.Prism.UnityExtensions.UnityBootstrapper.Run(Boolean runWithDefaultConfiguration)
           at Microsoft.Practices.Prism.Bootstrapper.Run()
           at EmailClient.App.OnStartup(StartupEventArgs e) in c:\Users\Roger\Google Drive\Karnaluks\Test Projects\EmailClient\EmailClient\App.xaml.cs:line 21
           at System.Windows.Application.&lt;.ctor>b__1(Object unused)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.DispatcherOperation.InvokeImpl()
           at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Windows.Threading.DispatcherOperation.Invoke()
           at System.Windows.Threading.Dispatcher.ProcessQueue()
           at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
           at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
           at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
           at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg)
           at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
           at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
           at System.Windows.Threading.Dispatcher.Run()
           at System.Windows.Application.RunDispatcher(Object ignore)
           at System.Windows.Application.RunInternal(Window window)
           at System.Windows.Application.Run(Window window)
           at System.Windows.Application.Run()
           at EmailClient.App.Main() in c:\Users\Roger\Google Drive\Karnaluks\Test Projects\EmailClient\EmailClient\obj\Debug\App.g.cs:line 50
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.IO.FileLoadException
           HResult=-2146234304
           Message=Could not load file or assembly 'Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
           FileName=Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
           FusionLog==== Pre-bind state information ===
    LOG: DisplayName = Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
     (Fully-specified)
    LOG: Appbase = file:///C:/Users/Roger/Google Drive/Karnaluks/Test Projects/EmailClient/EmailClient/bin/Debug/
    LOG: Initial PrivatePath = NULL
    Calling assembly : Microsoft.Practices.Prism.UnityExtensions, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: C:\Users\Roger\Google Drive\Karnaluks\Test Projects\EmailClient\EmailClient\bin\Debug\EmailClient.vshost.exe.Config
    LOG: Using host configuration file: 
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
    LOG: Redirect found in application configuration file: 3.5.0.0 redirected to 3.5.1.0.
    LOG: Post-policy reference: Microsoft.Practices.Unity, Version=3.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    LOG: Attempting download of new URL file:///C:/Users/Roger/Google Drive/Karnaluks/Test Projects/EmailClient/EmailClient/bin/Debug/Microsoft.Practices.Unity.DLL.
    WRN: Comparing the assembly name resulted in the mismatch: Build Number
    ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.</p>
  </blockquote>
  
  <pre><code>   InnerException: 
  </code></pre>