15

I am working on an ASP.NET Core v2.1 Razor Pages project in which I am working on implementing Auth0 for user authentication. After setting everything up, I attempted to build my project and am getting the following exception:

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

In order to set up Auth0, I had to install the Microsoft.Extensions.Primitives nuget package. However, when trying to build my project, this is the error I get. If I remove the package, when I try and build the project, I get the following error:

Version conflict detected for Microsoft.Extensions.Primitives. Install/reference 
Microsoft.Extensions.Primitives 5.0.0 directly to your project to resolve this issue.

The following code is where the exception is being thrown:

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
}

I have read that InplaceStringBuilder does not exist in Microsoft.Extensions.Primitives anymore so I am assuming this is causing the problem. However, I don't see InplaceStringBuilder being used anywhere so I can't seem to figure out what it is even needed for.

Does anyone know a way to resolve this issue?

BenTen
  • 333
  • 1
  • 5
  • 17
  • are you sure on asp.net core version and Primitives version? – Vivek Nuna Mar 01 '21 at 04:00
  • The target framework is .NET Core 2.1 and Primitives 5.0.0 is installed. – BenTen Mar 01 '21 at 04:05
  • Maybe you can try to update your package `Primitives` from 5.0.0 to 2.1.1. – Yinqiu Mar 01 '21 at 05:32
  • @Yinqiu, I tried this and it is still throwing the same exception, which I don't understand, since it is still saying it couldn't load from assembly Microsoft.Extensions.Primitives V 5.0.0 – BenTen Mar 01 '21 at 06:38

1 Answers1

15

Probably you have some package that uses Microsoft.Extensions.Primitives on Version >= 5.0.0

I had a similar problem a few days ago. In my scenario, I was working on an ASP.NET Core v2.1 WEB API and a dependency with a project that was using the package Microsoft.Extensions.Configuration.Abstractions on Version="5.0.0" caused the problem. I was able to solve the problem by downgrading that package from Version 5.0.0 to Version 2.1.0.

Salahuddin Ahmed
  • 4,854
  • 4
  • 14
  • 35
Fernando Penido
  • 166
  • 2
  • 4
  • Removing all the Microsoft.Extensions.* library references worked for me. – Mike67 Jul 17 '21 at 14:04
  • How to do the downgrading? – Denis G. Labrecque Jul 30 '21 at 19:29
  • @DenisG.Labrecque by using the `NuGet Package Manager`. You can choose any available version of a package and update. If you use NuGet Manager (interface) in Visual Studio, you'll be able to see the package dependencies before installing or updating. – Fernando Penido Aug 01 '21 at 20:25
  • 1
    Just got the problem also for a WPF app referencing a .net standard lib (these one reference the abstraction nuget), version 3.1.0 is working also – Jérémie Leclercq Aug 10 '21 at 14:37
  • Thanks, I had the same issue. I was able to use the deps.json file in the solution (after building) to investigate which package was causing the issue - it was actually a nuget package that I had written myself. Same as you, downgrading the Abstractions package resolved the error. – to6y Sep 02 '22 at 09:24