title: Unit tests pass with "dotnet test" but fail when run from Visual Studio 2017 Test Explorer
body: <p>My XUnit 2.2 tests all pass when run from the command line with <code>dotnet test</code>. When running them from Visual Studio 2017's Test Explorer some of the tests fail with Assembly Binding errors. </p>
  
  <p>My test project targets .Net 4.6.2 and references an ASP.Net Core 1.1 application also targeting .Net 4.6.2. The unit tests were working fine in VS 2015 prior to upgrading to the .NET Core 1.1 release tooling and Visual Studio 2017.</p>
  
  <p>The workaround was to create an <code>app.config</code> file for the test project and add all of the needed binding redirects to it via trial and error. I'm not sure <em>why</em> I have to do this, though.</p>
  
  <p>It appears that when using <code>dotnet test</code> the runtime uses the newer assembly versions without complaint. When running from Visual Studio, the redirects are necessary.</p>
  
  <p>Why is there a difference in the assembly binding behavior between these two methods of running the tests?</p>
  
  <p>Sample assembly binding error:</p>
  
  <pre><code>The operation failed.
  Bind result: hr = 0x80131040. No description available.
  
  Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
  Running under executable  C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe
  --- A detailed error log follows. 
  
  === Pre-bind state information ===
  LOG: DisplayName = Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
   (Fully-specified)
  LOG: Appbase = file:///C:/xx/xx/xx.Tests/bin/Debug/net462
  LOG: Initial PrivatePath = NULL
  LOG: Dynamic Base = NULL
  LOG: Cache Base = C:\Users\xxxxx\AppData\Local\Temp\a1ec4d3c-04ff-4fa0-9e56-129e799dd870
  LOG: AppName = a1ec4d3c-04ff-4fa0-9e56-129e799dd870
  Calling assembly : Serilog.Settings.Configuration, Version=2.2.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10.
  ===
  LOG: This bind starts in default load context.
  LOG: Using application configuration file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.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: Post-policy reference: Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
  LOG: GAC Lookup was unsuccessful.
  LOG: Attempting download of new URL file:///C:/xx/xx/xx.Tests/bin/Debug/net462/Microsoft.Extensions.Configuration.Abstractions.DLL.
  LOG: Assembly download was successful. Attempting setup of file: C:\xx\xx\xx.Tests\bin\Debug\net462\Microsoft.Extensions.Configuration.Abstractions.dll
  LOG: Entering download cache setup phase.
  LOG: Assembly Name is: Microsoft.Extensions.Configuration.Abstractions, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
  WRN: Comparing the assembly name resulted in the mismatch: Minor Version
  ERR: The assembly reference did not match the assembly definition found.
  ERR: Setup failed with hr = 0x80131040.
  ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
  </code></pre>
  
  <p>And the redirect needed to solve it:</p>
  
  <pre><code>&lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" culture="neutral" publicKeyToken="adb9793829ddae60" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.1.1.0" /&gt;"
   &lt;/dependentAssembly&gt;
  </code></pre>