none
No parameterless constructor defined for this object - When trying to add Controller

    Question

  • Hi Guys,

    I am trying to add a controller for two DB models I have added to my new project. I am getting this error when I try and create the controller.

    No parameterless constructor defined for this object. The error log is below.

    Finding the generator 'controller'...
    Running the generator 'controller'...
    Attempting to compile the application in memory.
    Attempting to figure out the EntityFramework metadata for the model and DbContext: 'Customer'
    info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
          User profile is available. Using 'C:\Users\tpgre\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
    Unable to create an object of type 'FlightSystemDBContext'. Add an implementation of 'IDesignTimeDbContextFactory<FlightSystemDBContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time. StackTrace:
       at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass12_3.<FindContextTypes>b__13()
       at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
       at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
       at Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore.EntityFrameworkModelProcessor.TryCreateContextUsingAppCode(Type dbContextType, Type startupType)
    No parameterless constructor defined for this object.No parameterless constructor defined for this object. StackTrace:
    
       at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor)
       at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
       at System.Activator.CreateInstance(Type type, Boolean nonPublic)
       at System.Activator.CreateInstance(Type type)
       at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass12_3.<FindContextTypes>b__13()
       at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
       at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
       at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
       at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)

    Monday, April 16, 2018 12:06 PM