-
Notifications
You must be signed in to change notification settings - Fork 311
Creating instance of TestServer throws exception after upgrading to VS 2017 #959
Comments
Can you post your project file so I can try to reproduce the issue? |
Hi John, Thanks for your reply. I have done some more digging and found that what is happening is that the test project doesn't pick up the config of the host application, and so it is missing the bindingRedirects which would normally be applied. Copying the config file of the host application into the test project, renaming it to app.config and setting it to 'copy always' fixed the problem. However, this led to a second problem where it would seem that any call to a Controller in a different assembly returns 404. Maybe I this should be registered as a separate issue, but I can't tell if this is related or not. I have created a project in which you can reproduce both problems. I have published the code here. The file 'README.txt' explains the exact steps to reproduce the issue. I look forward to your reply, Chris |
By the way, if you find in my sample that the test doesn't show up after converting to vs2017, change the following references in the MyTest project: |
@anurse has the binding redirect workaround |
microsoft/vstest#428 describes the issue and the workaround. |
Ok, thanks for the info. And is there any info on the second problem I reported? |
Seems like there are a few other issues involved. microsoft/vstest#196 We work around the issue with Gives these a try. |
Many thanks guys, these workarounds solved my problem and allow me to get on with enjoying VS2017. Just for anybody else stumbling on this issue, I'll summarize what I did below: Add a new file 'xunit.runner.json' to the test project containg the following code: {
"shadowCopy": false
} Then add the following code to the test project: <!-- Solves Problem#1 (binding error) https://github.com/Microsoft/vstest/issues/428. -->
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
<!-- Solves Problem#2 (404 when executing service calls hosted in other assemblies) -->
<!-- https://github.com/Microsoft/vstest/issues/196.-->
<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<!-- https://github.com/NuGet/Home/issues/4412. -->
<Target Name="CopyDepsFiles" AfterTargets="Build" Condition="'$(TargetFramework)'!=''">
<ItemGroup>
<DepsFilePaths Include="$([System.IO.Path]::ChangeExtension('%(_ResolvedProjectReferencePaths.FullPath)', '.deps.json'))" />
</ItemGroup>
<Copy SourceFiles="%(DepsFilePaths.FullPath)" DestinationFolder="$(OutputPath)" Condition="Exists('%(DepsFilePaths.FullPath)')" />
</Target> |
Closing since the issue is not in Hosting and there are tracking issues and workarounds for the known problems. |
@Chris197 thank you so much! we spent 2 full working days fighting with the integration tests on vs2017! |
@Chris197 an extra kudo from me!! 😎 |
* `dotnet migrate` all the projects, moving from project.json to .csproj * Created a solution file (dotnet new sln and dotnet sln add ...) capturing all of the projects to replace the equivalent global.json * Adjusted *some* of the test run batch files to account for new CLI format for invoking unit tests * Had to make some adjustments to TestServer integration tests to handling binding redirects properly as described by aspnet/Hosting#959 and microsoft/vstest#428
Worked prefectly, thanks a lot! I owe you a beer |
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:
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.
The text was updated successfully, but these errors were encountered: