Share via

Visual Studio, ASP .NET Core WebAPI, Add Controller Wizard (for EF) has stopped working

Michael 166 Reputation points
2026-05-17T20:46:44.2033333+00:00

I've created an ASP .NET Core WebAPI solution. I have successfully created 5 controllers using the Add Controller Wizard (API->API Controller with actions, using Entity Framework). Compiles and runs fine.

Now the wizard is not working. It fails silently but leaves text in the Output:

Initializing scaffolding model...

No properties found for

--model 'CB' Invalid

--model 'CB'

An error occurred.

The solution compiles without errors. I'm using the EF 8.27 versions of the needed packages.

If I drop a controller that successfully was added by the wizard before, I can't recreate the controller (so, I don't think this is the model at all). I cleaned, deleted obj and bin, rebooted. The usual stuff.

I can create and empty EF controller and I can get that to work but I really want the wizard to work correctly. I don't want to write all the methods by hand.

Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other

A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.

0 comments No comments

1 answer

Sort by: Most helpful
  1. AI answer

    2026-05-17T20:47:04.13+00:00

    The scaffolding engine is failing to resolve the model type when running the “API Controller with actions, using Entity Framework” wizard. The key is to repair the scaffolding environment and EF tooling that the wizard depends on.

    Use the following steps (in order) to restore the wizard:

    1. Verify required scaffolding packages are present In the Web API project’s .csproj, ensure the following packages exist with compatible versions (for ASP.NET Core + EF Core):
      • Microsoft.VisualStudio.Web.CodeGeneration.Design
      • Microsoft.EntityFrameworkCore.Tools
      • Microsoft.EntityFrameworkCore.Design
      • The EF Core provider you use (for example Microsoft.EntityFrameworkCore.SqlServer)
      Visual Studio normally adds these automatically when scaffolding controllers or MVC pages, as shown in the MVC and Web API tutorials:
      • Microsoft.VisualStudio.Web.CodeGeneration.Design
      • Microsoft.EntityFrameworkCore.Tools
      • Microsoft.EntityFrameworkCore.SqlServer
      If any are missing, add them via NuGet and rebuild the solution.
    2. Rebuild the solution before running the wizard The scaffolding engine uses reflection over the compiled assembly to find model and DbContext types. If the project is not building, or if the build is stale, the wizard may report messages like:
      • No properties found for --model 'CB'
      • --model 'CB' Invalid
      Build the solution (Build → Rebuild Solution) and confirm there are no compilation errors before opening the Add Controller wizard.
    3. Confirm the model and context types are valid For the model type CB that the wizard is complaining about:
      • Ensure CB is a public class in the project (or referenced project) and compiles.
      • Ensure it has public properties (the scaffolder expects properties to generate CRUD code).
      • Ensure the DbContext used by the wizard exposes a DbSet<CB> property.
      The scaffolder for MVC and Web API controllers with EF requires a valid model class and a valid DbContext, similar to the examples where Student/SchoolContext, Movie/MvcMovieContext, or TodoItem/TodoContext are used.
    4. Repair the scaffolding tool chain (CLI side) Even when using Visual Studio’s wizard, the underlying scaffolding engine is the same as the CLI dotnet-aspnet-codegenerator. If it is in a bad state, reinstalling it and its supporting packages can fix silent failures. In the project folder (where the .csproj lives), run:
         dotnet tool uninstall --global dotnet-aspnet-codegenerator
         dotnet tool install --global dotnet-aspnet-codegenerator
         dotnet tool update --global dotnet-aspnet-codegenerator
         
         dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
         dotnet add package Microsoft.EntityFrameworkCore.Design
         dotnet add package Microsoft.EntityFrameworkCore.SqlServer
         dotnet add package Microsoft.EntityFrameworkCore.Tools
      
      Then rebuild the project.
    5. Test scaffolding via CLI To verify that the scaffolding engine itself works for the CB model and its context (for example MyDbContext), run from the project folder:
         dotnet aspnet-codegenerator controller \
             -name CBController \
             -async -api \
             -m CB \
             -dc MyDbContext \
             -outDir Controllers
      
      If this succeeds, the underlying scaffolding engine is healthy; the Visual Studio wizard should also work again. If it fails with the same “No properties found” message, the issue is with the model or context definition (step 3).
    6. Clear intermediate output and NuGet caches Since deleting bin/obj did not help, also clear NuGet caches and restore packages:
      • Close Visual Studio.
      • Delete bin and obj folders again.
      • Clear NuGet caches (for example via nuget locals all -clear or Visual Studio’s NuGet options).
      • Reopen the solution and let NuGet restore packages.
      • Rebuild and retry the wizard.
    7. As a fallback, scaffold a similar controller and adjust If the wizard still fails specifically for CB but works for other models, scaffold a controller for a similar model that works, then copy/rename the generated controller and adjust the type names and DbSet usage manually. This avoids writing all methods from scratch while you continue to investigate why CB is being rejected.

    These steps align with how ASP.NET Core scaffolding is expected to work in Visual Studio and via the CLI, and they address the typical causes of “No properties found for --model” and silent wizard failures.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.