Creating instance of TestServer throws exception after upgrading to VS 2017 #959
Description
Hi, after successfully converting a VS2015 ASP.NET Core solution to VS2017, the only thing that I can't get to work is the integration test I had set up using Microsoft.AspNetCore.TestHost.TestServer (which, when it works is awesome by the way). The code I use to run is very simple:
var builder = new WebHostBuilder().UseStartup<Startup>();
var server = new TestServer(builder);
At the point at which it tries to construct TestServer, the following exception is thrown:
System.IO.FileLoadException: 'Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
Extra info under 'FusionLog' states:
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:/<ommitted>/bin/Debug/net451 LOG: Initial PrivatePath = NULL Calling assembly : Microsoft.ApplicationInsights.AspNetCore, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: This bind starts in default load context. LOG: Using application configuration file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\ENTERPRISE\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: Attempting download of new URL file:///C:/<ommitted>/bin/Debug/net451/Microsoft.Extensions.Configuration.Abstractions.DLL. WRN: Comparing the assembly name resulted in the mismatch: Build Number ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
I am riding the LTS train of dotnet core (v 1.0.3) and using Microsoft.AspNetCore.TestHost v 1.0.2. Looking at the other projects in my solution, any references to Microsoft.Extensions.Configuration.Abstractions are transitively included through other dependencies and are all version 1.0.2. All projects target framework dotnet451 (not appcore). This all works fine in my VS2015 solution and I haven't changed the versions going to VS2017. What I have tried:
- Deleting all bin and obj directories, restart and recompile after everything I changed.
- Upgrading Microsoft.AspNetCore to v 1.0.4
- targeting dotnet452 instead of dotnet451
- Reproducing the situation by creating a simple new VS2017 project. This error was reproducable, but was solved when I upgraded Microsoft.AspNetCore to v 1.0.4. Unfortunately this same action did not solve the problem in my main solution.
- Adding a bindingRedirect in web.config to force the said library to use version 1.0.2. but noticed no difference, in fact, I then saw that the application config file in the bin directory already contains this redirect (and others) as generated by dot net.
The next thing I'm going to try is to upgrade everything to the 1.1.1 FTS version, although I feel that really the LTS should just work.
Any help would be much appreciated.