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(IOptions
1 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?
CodePudding user response:
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.
CodePudding user response:
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