Aspnetcore: Could not load file or assembly 'Microsoft.AspNetCore.CookiePolicy, Version=2.2.0.0

Created on 5 Jan 2019  路  4Comments  路  Source: dotnet/aspnetcore

Moving from dotnet/core-setup#4923 on behalf of @JulidaRocks

Steps to reproduce

Upgraded from dotnet core 2.1 to 2.2. When running the integration tests, an exception is thrown when initializing TestServer with
var testServer = new Microsoft.AspNetCore.TestHost.TestServer(webHostBuilder);

Expected behavior

Should create the test server object

Actual behavior

throws exception

Environment data

Stack trace:

at .Api.Startup.ConfigureServices(IServiceCollection services)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at Microsoft.AspNetCore.TestHost.TestServer..ctor(IWebHostBuilder builder, IFeatureCollection featureCollection)
at .Api.IntegrationTests.IntegrationTestFixture.CreateServer(String currentDirectory, Boolean authenticated, Boolean useAdAuthentication) in .Api.IntegrationTestsIntegrationTestFixture.cs:line 50
at .Api.IntegrationTests.Ability.AbilityCategoryIntegrationTests.Initialize() in .Api.IntegrationTestsAbilityAbilityCategoryIntegrationTests.cs:line 41

Packages in .Api-project

```xml
















Packages in .Api.IntegrationTests-project:

```xml
<ItemGroup>
    <PackageReference Include="Equ" Version="2.0.2" />
    <PackageReference Include="FluentAssertions" Version="5.5.3" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="NUnit" Version="3.11.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
    <PackageReference Include="SimpleInjector" Version="4.4.3" />
    <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
  </ItemGroup>
area-mvc

Most helpful comment

I was having the issue with the Microsoft.AspNetCore file or assembly, and solved it by adding a package reference to the test project, like so:
<PackageReference Include="Microsoft.AspNetCore.App" />

All 4 comments

Any suggestions?

Also getting something similar for our integration tests - Could not load file or assembly 'Microsoft.AspNetCore.Cors, Version=2.2.0.0

I was having the issue with the Microsoft.AspNetCore file or assembly, and solved it by adding a package reference to the test project, like so:
<PackageReference Include="Microsoft.AspNetCore.App" />

@mrlund thanks, this fixed the issue!

Was this page helpful?
0 / 5 - 0 ratings