ASP.Net Core 2.2 MVC Error g.cshtml.cs: The type or namespace name ErrorViewModel could not be found (are you missing a using directive or an assembly reference). File Error.g.cshtml.cs

ASP.Net Core 2.2 MVC Error g.cshtml.cs: The type or namespace name ErrorViewModel could not be found (are you missing a using directive or an assembly reference). File Error.g.cshtml.cs


Problem: When working in ASP.net core 2.2 MVC project and you decide to scaffold the MVC component from the database first using Entity Framework. The error comes about when you already had DTO database table class Models in a Models Folder and then you decide to generate a new version of Database tables into C# classes, because of some changes made to database tables.

[NB] You might get an error when compiling your project with Razor Engine. This is because Razor Engine still references old files in it's Cache System. 

Solution: Don't panic, because if you do, you will block your thinking capacity to resolve the problem. Carefully review the error List in the Output section of Visual Studio and then examine those files listed in the File tab of the Output Console.

- There is a big chance that those Razor View files do not reference the newly scaffolded/generated DTO's (classes mimicking the Database tables)

- Examine Razor View File shown as [FileName]..g.cshtml.cs and then include this directive: @using ProjectName.FolderWhereYourNewDTOsAreGenerated.ClassFileName do this in all files emitting the exception and the error will go.