I was following a tutorial from Microsoft found at https://learn.microsoft.com/en-us/training/modules/create-razor-pages-aspnet-core/
At one point it instructs to add a folder under the root project called "Services". Within that folder is a file which needs to be accessed. Upon creating the project, another folder called "Models" was automatically created under the root folder.
I include the two lines at the top of another file:
using RazorPagesDoughnuts.Services; using RazorPagesDoughnuts.Models;
The Models statement works no problem. The Services statement generates the error. I have searched many resources and cannot find a solution.
I am using vscode 1.71.2 and .net 6.0
2
Answers
The namespace provided in the file
DoughnutService.cs
is probably not correct. Change that toRazorPagesDoughnuts.Services
and check.In C#
using
statements are not based on file structure, but rather on namespaces. If there aren’t any files with the statementnamespace RazorPagesDoughnuts.Services
in the project, then you will not be able to reference it in other files.Make sure that
DoughnutService.cs
contains this namespace statement.