This issue I encountered when I tried to scaffold database tables to Entity framework core entities in a Asp.Net Core project using scaffold-dbcontext command. After scaffolding, when I tried to run my project I could see this run time error.
Error Details:
InvalidOperationException: The DbContext of type ‘IQContext’ cannot be pooled because it does not have a public constructor accepting a single parameter of type DbContextOptions or has more than one constructor.
Microsoft.EntityFrameworkCore.Internal.DbContextPool..ctor(DbContextOptions options)
InvalidOperationException: The DbContext of type ‘Context’ cannot be pooled because it does not have a public constructor accepting a single parameter of type DbContextOptions or has more than one constructor.
Microsoft.EntityFrameworkCore.Internal.DbContextPool..ctor(DbContextOptions options)
Problem
If we observe the issue, we can understand the issue with the context class. Also, it indicates that the issue is with the constructor. Mainly issue is concerned with more than one constructor.
Here is the screenshot of DbContext class, where the issue is throwing. If we observe the screenshot we can able to see there are two constructors. This class is generated by the Scaffolding command to generate a context class from the database first approach.
Solution
To solve this issue, I am supposed to remove the empty constructor with no parameter. Once I removed the non-parametrized constructor, the application could run without any run time errors.
Video Tutorial
Summary
In this issue, If we could read the error description, we will get a hint to solve the issue. Most of the errors would be self-explanatory and a few error descriptions would be of course confusing.