Skip to content

Error when following one of the tutorials #1923

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

Closed
jgoshi opened this issue Feb 2, 2017 · 8 comments
Closed

Error when following one of the tutorials #1923

jgoshi opened this issue Feb 2, 2017 · 8 comments

Comments

@jgoshi
Copy link

jgoshi commented Feb 2, 2017

When I tried to follow this tutorial:
https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-model

At the part where I try to add the controller I get the following error (see screenshot).
image

Note that I can build the project successfully. But cannot add the controller. Not sure if this is a user error, but if not it's a bad bug.

Microsoft Visual Studio Enterprise 2017 RC
Visual Studio/15.0.0-RC4+26129.0.d15rel

@danroth27 @mlorbetske

@Rick-Anderson
Copy link
Contributor

@jgoshi I've seen this error before. Can you try the following:

  • Exit/restart VS17 and try to scaffold again.
  • If above fails, create a new project with simple model and scaffold.

@prafullbhosale
Copy link
Contributor

@jgoshi can you provide the contents of your csproj file?
And also the log from the output window if possible?

@jgoshi
Copy link
Author

jgoshi commented Feb 3, 2017

Exit/restart VS17 and try again failed. Here are the contents from the output window.
D:\dotnetcli\artifacts\win10-x64\stage2\dotnet.exe aspnet-codegenerator --project "C:\Users\jgoshi\documents\visual studio 2017\Projects\MvcMovie\MvcMovie\MvcMovie.csproj" --no-build controller --force --controllerName MoviesController --model MvcMovie.Models.Movie --dataContext MvcMovie.Data.ApplicationDbContext --relativeFolderPath Controllers --referenceScriptLibraries --useDefaultLayout
Command Line: --project C:\Users\jgoshi\documents\visual studio 2017\Projects\MvcMovie\MvcMovie\MvcMovie.csproj --no-build controller --force --controllerName MoviesController --model MvcMovie.Models.Movie --dataContext MvcMovie.Data.ApplicationDbContext --relativeFolderPath Controllers --referenceScriptLibraries --useDefaultLayout
Microsoft (R) Build Engine version 15.1.539.38876
Copyright (C) Microsoft Corporation. All rights reserved.
Command Line: --no-dispatch --port-number 30855 --project C:\Users\jgoshi\documents\visual studio 2017\Projects\MvcMovie\MvcMovie\MvcMovie.csproj --no-build controller --force --controllerName MoviesController --model MvcMovie.Models.Movie --dataContext MvcMovie.Data.ApplicationDbContext --relativeFolderPath Controllers --referenceScriptLibraries --useDefaultLayout --dispatcher-version 1.0.0-msbuild3-final
Finding the generator 'controller'...
Running the generator 'controller'...
Attempting to compile the application in memory with the modified DbContext
Attempting to figure out the EntityFramework metadata for the model and DbContext: Movie
No parameterless constructor was found on 'ApplicationDbContext'. Either add a parameterless constructor to 'ApplicationDbContext' or add an implementation of 'IDbContextFactory' in the same assembly as 'ApplicationDbContext'. StackTrace:
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass12_3.b__13()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
No parameterless constructor defined for this object. at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)

at Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore.EntityFrameworkServices.TryCreateContextUsingAppCode(Type dbContextType, Type startupType)
No parameterless constructor defined for this object. StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.b__6_0() at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)

at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at System.Activator.CreateInstance(Type type, Boolean nonPublic)

at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args) at System.Activator.CreateInstance(Type type)

at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass12_3.b__13()
RunTime 00:00:06.29

@jgoshi
Copy link
Author

jgoshi commented Feb 3, 2017

And here is the csproj file:

MvcMovie.zip

@prafullbhosale
Copy link
Contributor

Worked with @jgoshi offline. The issue seemed to be a bad package in the local nuget cache.
Clearing out the local nuget cache and retrying the scenario worked fine.

@aspnet-hello
Copy link

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.

@davidalpert
Copy link

davidalpert commented Dec 30, 2017 via email

@davidalpert
Copy link

davidalpert commented Dec 30, 2017 via email

natemcmaster pushed a commit that referenced this issue Nov 14, 2018
@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants