'ASP.NET Core Web API - How to resolve Detected package version outside of dependency constraint

In my ASP.NET Core-6 Web API, as I tried to install:

Install-Package AutoMapper.Extensions.Microsoft.DependencyInjection -Version 11.0.0

through the Nugget package, I got this error:

Detected package version outside of dependency constraint: Duende.IdentityServer.EntityFramework.Storage 5.2.0 requires AutoMapper (>= 10.0.0 && < 11.0.0) but version AutoMapper 11.0.1 was resolved.

While trying to resolve it, I install AutoMapper ver-11.0.1

Then the application flagged AutoMapper that was installed.

How do I resolve this?

Thanks



Solution 1:[1]

TLDR: Downgrade AutoMapper.Extensions.Microsoft.DependencyInjection to 8.1.1 that depends on AutoMapper (>= 10.1.1 && < 11.0.0)

https://www.nuget.org/packages/AutoMapper.Extensions.Microsoft.DependencyInjection/8.1.1

Long answer:

I got a similar warning or error as well but for me it was when installing NuGet AutoMapper:

NU1608 Detected package version outside of dependency constraint: Duende.IdentityServer.EntityFramework.Storage 5.2.0 requires AutoMapper (>= 10.0.0 && < 11.0.0) but version AutoMapper 11.0.1 was resolved.

You probably have the NuGet Microsoft.AspNetCore.ApiAuthorization.IdentityServer or similar installed.

https://www.nuget.org/packages/Microsoft.AspNetCore.ApiAuthorization.IdentityServer

If you look at Microsoft.AspNetCore.ApiAuthorization.IdentityServer NuGet dependencies you will see:

  • net6.0
  • Duende.IdentityServer (>= 5.2.0)
  • Duende.IdentityServer.AspNetIdentity (>= 5.2.0)
  • Duende.IdentityServer.EntityFramework (>= 5.2.0)
  • Duende.IdentityServer.EntityFramework.Storage (>= 5.2.0)
  • Duende.IdentityServer.Storage (>= 5.2.0)
  • Microsoft.AspNetCore.Authentication.JwtBearer (>= 6.0.5)
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 6.0.5)
  • Microsoft.AspNetCore.Identity.UI (>= 6.0.5)
  • Microsoft.Extensions.Http (>= 6.0.0)
  • Newtonsoft.Json (>= 13.0.1)

You could solve it by manually updating libraries below:

  • Duende.IdentityServer
  • Duende.IdentityServer.AspNetIdentity
  • Duende.IdentityServer.EntityFramework
  • Duende.IdentityServer.EntityFramework.Storage
  • Duende.IdentityServer.Storage

Duende.IdentityServer.EntityFramework.Storage 6.1.0 has the following dependencies which will fix your error:

  • net6.0
  • AutoMapper (>= 11.0.0 && < 12.0.0)
  • Duende.IdentityServer.Storage (>= 6.1.0)
  • Microsoft.EntityFrameworkCore.Relational (>= 6.0.0)

https://www.nuget.org/packages/Duende.IdentityServer.EntityFramework.Storage/

However this will probably give you this exception when running your code for endpoints.MapRazorPages();.

System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types. Method 'get_ServerSideSessions' in type 'Microsoft.AspNetCore.ApiAuthorization.IdentityServer.ApiAuthorizationDbContext`1' from assembly 'Microsoft.AspNetCore.ApiAuthorization.IdentityServer, Version=6.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.'

I have asked Microsoft to update Microsoft.AspNetCore.ApiAuthorization.IdentityServer so it is compatible with latest Duende.IdentityServer.EntityFramework.Storage which would fix the problem.

https://github.com/dotnet/aspnetcore/issues/41897

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ogglas