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

Unable to create an object of type 'MvcMovieContext' #7636

Closed
msharps opened this issue Jul 15, 2018 — with docs.microsoft.com · 11 comments
Closed

Unable to create an object of type 'MvcMovieContext' #7636

msharps opened this issue Jul 15, 2018 — with docs.microsoft.com · 11 comments
Assignees
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue
Milestone

Comments

Copy link

msharps commented Jul 15, 2018

Encountered the following error when executing "Add-Migration Rating":

Unable to create an object of type 'MvcMovieContext'. Add an implementation of 'IDesignTimeDbContextFactory<MvcMovieContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.

Visiual Studio Community 2017 version 15.7.5
.NET Framework version 4.6.01590


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@Rick-Anderson
Copy link
Contributor

@msharps I'm not sure what you did wrong but that error is misleading. You might compare your code to the download to see what when wrong.

@Rick-Anderson Rick-Anderson self-assigned this Jul 16, 2018
@Rick-Anderson Rick-Anderson added Source - Docs.ms Docs Customer feedback via GitHub Issue P4 labels Jul 16, 2018
@Rick-Anderson Rick-Anderson added this to the Backlog milestone Jul 16, 2018
Copy link

You need to add an implementation of IDesignTimeDbContextFactory where the ApplicationDbContext is put (in my case it's in Data folder)
Sample code:
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory
{
public StartProjectContext CreateDbContext(string[] args)
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var builder = new DbContextOptionsBuilder();
builder.UseSqlServer("Server=(localdb)\mssqllocaldb;Database=StartProjectContext-af90bdd0-0ac9-4522-b642-e1bec9d28c74;Trusted_Connection=True;MultipleActiveResultSets=true");
return new StartProjectContext(builder.Options);
}
}

@Rick-Anderson
Copy link
Contributor

Rick-Anderson commented Aug 21, 2018

@hoangpham0501 You do not have to add an implementation of IDesignTimeDbContextFactory

The instructions in the tutorial are complete and correct.

Copy link

Maybe you should check it again :D I have followed this tutorial step by step and I got same error with msharps. So I added an implementation of IDesignTimeDbContextFactory and then it worked :D

@paulowendevelopment
Copy link

I'm getting exactly the same error running Dotnet version 2.1.202

Copy link

As this tutorial is from 2016, I'd imagine it's quite feasible for something to have changed, so saying "The instructions in the tutorial are complete and correct." is quite a bold statement?

@Rick-Anderson
Copy link
Contributor

Copy link

@Rick-Anderson Upgrading the latest version of the .NET Core SDK does not make this problem go away. Also, following the tutorial to the T does not make the error go away.

@paulowendevelopment
Copy link

@jdmagic21 no you're right it is misleading, I even downloaded the latest from the website and it made no difference. What fixed it for me was to update the Nuget packages. Right click on your project in solution explorer and select manage Nuget packages, and update the ones that have a little blue arrow . Hope that fixes it for you!

Copy link

Make sure that your progam.cs file is correct. Use BuildWebHost().

@Rick-Anderson
Copy link
Contributor

Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

5 participants