0

Anyone managed to install Microsoft.Identity.Web and run on ASP.NET Core 2.1?

I've got quite a few ASP.NET Core 2.1 API projects as they have to refer to DLLs targeting .NET 4.7.2. The apps use Azure AD as authentication and I recently tried hours to upgrade to Microsoft.Identity.Web without success. It depends on Microsoft.Extensions.* 5.0 or later. It causes Kestrel to throw an error right after startup:

System.TypeLoadException: Could not load type 'Microsoft.Extensions.Primitives.InplaceStringBuilder' from assembly 'Microsoft.Extensions.Primitives, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

at Microsoft.Net.Http.Headers.DateTimeFormatter.ToRfc1123String(DateTimeOffset dateTime, Boolean quoted)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.DateHeaderValueManager.SetDateValues(DateTimeOffset value)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.CreateServiceContext(IOptions1 options, ILoggerFactory loggerFactory) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer..ctor(IOptions1 options, ITransportFactory transportFactory, ILoggerFactory loggerFactory)

It seems that a method removed when Extentions.Primitive became 5.0 that is required to run Kestrel. Any workaround?

Additional note (13/Oct/21):

As Microsoft.Extensions.Primitives has not been installed explicitly, it is not shown on the Nuget package list, therefor impossible to downgrade. If I try install older version such as 2.1.6 explicitly, it refuses with the error:

NU1605: Detected package downgrade: Microsoft.Extensions.Primitives from 5.0.0 to 2.1.6. Reference the package directly from the project to select a different version. test21 -> Microsoft.Identity.Web 1.18.0 -> Microsoft.Extensions.Caching.Memory 5.0.0 -> Microsoft.Extensions.Primitives (>= 5.0.0) test21 -> Microsoft.Extensions.Primitives (>= 2.1.6)

yosh
  • 231
  • 3
  • 7
  • Have you tried to downgrade Microsoft.Extensions.primitives to version less than 5 ex: 3.1 or 2.1 .Try uninstall and install again if direct version downgrade or upgrade doesn't work. – kavyaS Oct 11 '21 at 18:53
  • Thanks. I've added note. – yosh Oct 13 '21 at 13:07
  • Have you tried to uninstall the package before installing the required version and rebuilding the project? If that was done ,Have you got to check and try any of [these](https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1605) or [this](https://stackoverflow.com/questions/42709533/detected-package-downgrade-warning-dotnet-core-vs-2017) ? – kavyaS Oct 18 '21 at 04:40
  • As stated I cannot uninstall or downgrade something doesn’t exist. If you have a working example, can you kindly share, github or edit your answer to include csproj? – yosh Oct 19 '21 at 09:01

2 Answers2

0

You can downgrade the package from Version 5.0.0 to Version 2.1.0 through Microsoft.Extensions.Primitives to solve the error.

By using NuGet Package Manager. You can select any available version of the package and update it.

If you use the NuGet manager (interface) in Visual Studio, you will be able to view package dependencies before installing or updating.

Tupac
  • 2,590
  • 2
  • 6
  • 19
0

I was working on an ASP.NET Core web api 2.1 . I had a similar problem when I tried with Microsoft identity. As you said Microsoft.Identity.Web has a dependency on Microsoft.Extensions.Primitives on Version = 5.0.0. I was able to solve the problem by downgrading that package from of Microsoft.Extensions.Primitives Version 5.0.0 to Version 2.1.0 and also by downgrading Microsoft.Extensions.Configuration.Abstractions to 2.1.0 which it depends on but you may also try for other versions ,if the error doesn’t occur.Then you may try the same with microsoft identity . When you do that save and close and start the application again.

Other work arounds

  • Sometimes if that doesn’t work , you may have missed adding that particular dependencies in cs.proj file or may have missed adding packagereference similar to error .So please check that too.

  • If not try deleting the bin /obj folder having those dependencies or just adding those dependencies or target frame works

  • Or you can resolve the issue by executing update command in package manager console by

    Update-Package -reinstall -Project MyProject

kavyaS
  • 8,026
  • 1
  • 7
  • 19
  • Will this not cause problems or errors when running the application? Since Microsoft.Identity.Web, is dependant on 5.0. – Tim Chermin Sep 06 '22 at 13:01