Improve exception messages for "no data store configured" #2227
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
type-bug
Milestone
We have seen people hit this exception several times in the betas: #2191 #2156 #2094.
The current exception message (No data stores are configured. Configure a data store by overriding OnConfiguring in your DbContext class or in the AddDbContext method when setting up services.) does not account for one of the common causes: customers will often have their derived DbContext correctly setup in their service configuration but will then bypass DI in the creation of the context by creating the context with the new keyword.
I believe we should try to say something more helpful in the exception message, e.g. something like this:
No data stores are configured. You can configure a data store by calling the AddDbContext method when setting up services and then instantiating the derived DbContext class using dependency injection, or by overriding OnConfiguring in your DbContext class.
Note that the fact it is at all possible to new a DbContext without passing any parameters to the constructor is an unfortunate effect of the decision we made to enable default constructors to work with ASP.NET and to have a DbContext with only a default constructor in the default application templates. We could also revert that decision although it has some unwanted consequences.
The text was updated successfully, but these errors were encountered: