dotnet / dotnet/Scaffolding

A type with the name "ModelName" does not exist when creating MVC Controller with views

Open
#1,702 30 comments 0 reactions 0 assignees View on GitHub
area-scaffolding customer-reported
Dominant language
C#
Stars
818
Forks
260
Avg merge
1d 8h
Merged PRs (30d)
10

Description

Trying to add a new controller using "Add MVC Controller with views, using Entity Framework" option fails with following error.

There was an error running the selected code generator:
'A type with the name __ does not exist.

The Code Generation Log is as below:

Finding the generator 'controller'...
Running the generator 'controller'...
A type with the name SportsWeek.Models.Models.Block does not exist
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.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)

1. The referenced Model is in a separate assembly.
2. Controller is generated fine if it is an empty MVC Controller

Microsoft.VisualStudio.Web.CodeGeneration.Design version: 6.0.0
Target framework: .NET 6.0
Operating system: Windows 11 Pro
IDE: Visual Studio Community 2022

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.