37

I have updated Visual studio 2019 to version 16.4.0. This version includes .NET Core SDK 3.1.100.

After that, I have tried to run some Unit Tests that I have on a project with Target Framework 2.2 but it's not being able to do so. It gives the following error:

Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process exited with error: It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '2.2.0' was not found.
  - The following frameworks were found:
      3.1.0 at [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
You can resolve the problem by installing the specified framework and/or SDK.

If I go to the aforementioned path I only found a 3.1.0 folder. If I list the installed SDKS I get this:

dotnet --list-sdks 
2.1.602 [C:\Program Files\dotnet\sdk]
2.1.700 [C:\Program Files\dotnet\sdk]
2.1.701 [C:\Program Files\dotnet\sdk]
2.1.801 [C:\Program Files\dotnet\sdk]
2.1.802 [C:\Program Files\dotnet\sdk]
2.2.100 [C:\Program Files\dotnet\sdk]
2.2.202 [C:\Program Files\dotnet\sdk]
2.2.207 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
2.2.301 [C:\Program Files\dotnet\sdk]
2.2.401 [C:\Program Files\dotnet\sdk]
2.2.402 [C:\Program Files\dotnet\sdk]
3.1.100 [C:\Program Files\dotnet\sdk]

If I ask for the installed runtimes I get this:

dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

So, I see Microsoft.AspNetCore.App', version '2.2.0' installed on the listed runtimes.

On the other hand, If I do: 'dotnet test' on the Unit Test project from within the Package Manager Console the tests are being run.

I also have Visual Studio Code installed and without any change, I can even Debug those Tests.

So, I'm a little bit lost here and I have tried for instance to manually copy the 2.2.0 Folder from C:\Program Files\dotnet\shared\ but after that, I got other errors while trying to run the tests.

Could anyone help me or point me in the right direction.

Sebastian Inones
  • 1,561
  • 1
  • 19
  • 32
  • 2
    I had a very similar error that I was able to solve by removing the reference to Microsoft.NET.Test.Sdk.dll in the package references of the Test projects. But I believe changing the option to use 64-bit architecture for running/debugging tests works too. – Dylan Nicholson Dec 15 '19 at 20:19

4 Answers4

93

After looking at the solution from @coloradoeos I discovered a different way to solve this without needing to install an x86 version.

Simply go to Test > Process architecture for anyCPU projects > x64

Tests should run normally after selecting x64.

enter image description here

Xeno-D
  • 2,175
  • 11
  • 15
  • 4
    I have tried your solution and it works well. In addition, there is no need to download and install anything extra, it's only needed to change the **CPU to X64**. The only question I still wonder is what happened and why it stops working after **Visual Studio Update**. I guess that configuration was changed without notice. – Sebastian Inones Dec 11 '19 at 10:02
  • Great find! Thank you! – Fred Dec 27 '19 at 16:01
  • 3
    I keep getting burned by this, then finding my wau digging through search results until I eventually get back to here, realizing I've been here before. This seems like it could be a bug. – James John McGuire 'Jahmic' Jan 23 '20 at 11:15
12

I'll refer you to this link.

The root cause appeared to be the lack of an x86 .NET Core 2.2 SDK instance under the following directory "C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App".

I only had a 3.1 version present, so I specifically downloaded an x86 version of the 2.2 SDK and installed it. Once I did that, the testhost ran my unit tests from Visual Studio (VS) just fine. I never uninstalled the old version of the SDK, so this must be an issue with the update process for the framework/VS.

RobC
  • 22,977
  • 20
  • 73
  • 80
coloradoeos
  • 121
  • 3
  • 1
    As you said, in my case **I never uninstalled any SDK**, I only did the update. As the link you referred stated: "Visual Studio **test runner seems to use x86 version** of .NET core SDK, so if you uninstall it (leaving only x64 version) you are not able anymore to run tests based on that .NET core version with Test Explorer." – Sebastian Inones Dec 10 '19 at 09:43
0

If you have the same issue in Azure build pipeline. change the target platform from in your test project to X64.

Visual Studio was configured to run AnyCPU tests as x86, but only the x64 SDK was installed. set VS to use x64 for AnyCPU tests. Also Upgraded to Microsoft.NET.Test.Sdk to the latest version.

And also in my case, I had to add a specific .NET core version to build pipeline. Find specific .NET core version Here enter image description here

tech-gayan
  • 1,373
  • 1
  • 10
  • 25
0

Try changing project framework to the ones that are found i.e 3.1 or 5.0: Right click on project -> Properties -> Application -> Target framework enter image description here

Priyank Kotiyal
  • 241
  • 2
  • 13