Check the .Net versions of all your projects in the solution explorer. In my case, it was .Net 6.0.1 in 2 projects and .Net 6.2.0 in the 3rd project so I changed the version of the third project and it worked.
To do so:
- Right click the solution name in solution explorer.
- Select ‘Manage Nuget Packages for Solution’.
- Select ‘Microsoft.EntityFramewokCore’.
- On the Right Side, Check if all projects in the solution have same version, If not, uninstall the package for the project that has different and install the same version as the other projects.
- Clean and Rebuild the Solution.