Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to create DbContext due to GetDatabaseLock method missing in Npgsql EF Core 9.x

I'm working on an ASP.NET Core project using Entity Framework Core and Npgsql for PostgreSQL. I'm trying to create a DbContext to manage my database, but I'm encountering the following error when I try to add a migration or run the application:

Unable to create a 'DbContext' of type 'RuntimeType'. The exception 'Method 'GetDatabaseLock' in type 'Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.Internal.NpgsqlHistoryRepository' from assembly 'Npgsql.EntityFrameworkCore.PostgreSQL, Version=9.0.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' does not have an implementation.' was thrown while attempting to create an instance.

I've confirmed that all my Entity Framework Core and Npgsql packages are on version 9.x, but the issue persists. The following includes a list of what I have tried to fix the issue

  • Verified all package versions are aligned at 9.x
  • Cleared NuGet cache and reinstalled the packages
  • Attempted to downgrade to a stable version (7.x) which resolved the issue, but I need to use 9.x features
  • Cleaned and rebuilt the project multiple times
like image 728
Ziad Diyaa Avatar asked Sep 02 '25 03:09

Ziad Diyaa


1 Answers

Upgrading to 9.0.2 for Npgsql.EntityFrameworkCore.PostgreSQL solved for me.

like image 200
Sk Shahnawaz-ul Haque Avatar answered Sep 05 '25 00:09

Sk Shahnawaz-ul Haque