Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF Migrations Assumes Something is wrong with the Implementation of DbContext classes if an error is thrown in ConfigureServices during startup #9175

Closed
MisterJames opened this issue Jul 13, 2017 · 1 comment

Comments

@MisterJames
Copy link

I had a small detour/goose chase when I added a migration where I started getting the following error from the command line when creating migrations:

An error occurred while calling method 'ConfigureServices' on startup class 'Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Error: Value cannot be null.
Parameter name: assembly

In spite of the error, migrations were created fine, and the database was able to be updated, but I couldn't figure out where the error was coming from. It turns out that I added AutoMapper to the project and added a call to services.AddAutoMapper() in ConfigureServices and neglected to pass in the assembly parameter (as the error alludes to).

Although I was able to figure this out, and perhaps AutoMapper should be more verbose in its own error, I think it was a little misleading for EF to suggest adding an IDbContextFactory in this case as a course of correction.

Steps to reproduce

  1. Add AutoMapper to a project with EF Core.
  2. Add the call to services.AddAutoMapper(); to ConfigureServices
Console.WriteLine("Hello World!");

Further technical details

EF Core version: CoreDesign 1.1.1, Tools 1.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win10
IDE: Visual Studio 2017

@ajcvickers
Copy link
Contributor

@MisterJames For 2.0, we have updated the message here to make it more apparent that the process continued and was able to use a different mechanism to get your context instance. Closing a duplicate of #9073. See also #9076.

@ajcvickers ajcvickers marked this as a duplicate of #9073 Jul 17, 2017
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants