Could not load type 'Context' from assembly 'Microsoft.AspNetCore.Hosting, Version=3.0.0.0
Asked Answered
C

1

19

Where using .netcore 2.2 an upgrade to .netcore 3.0

This is the error that we encounter when running unit test:

"Could not load type 'Context' from assembly 'Microsoft.AspNetCore.Hosting, Version=3.0.0.0"

Conchitaconchobar answered 1/8, 2019 at 5:7 Comment(0)
G
26

These steps work on our project:

  1. Remove old packages
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Cors" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
  1. Install
    Microsoft.AspNetCore.Mvc.Testing 3.0.0-preview7.19365.7
  1. Update Startup.cs
    .AddApplicationPart(Assembly.Load("YourProjectControllerNamespace"))

Gameto answered 2/8, 2019 at 7:13 Comment(2)
I have the same problem. Could you share this AddAppilcationPart in more detail, I'm not sure what assembly to load.Cytotaxonomy
Had the same issue and for me it was enough to do step 1 and 2 to make it work again (but since 3.0 is GA I didn't have to use a preview version).Grivation

© 2022 - 2024 — McMap. All rights reserved.