Home > Mobile >  I'm getting a CS0234 "The type or namespace name "Services" does not exist in th
I'm getting a CS0234 "The type or namespace name "Services" does not exist in th

Time:09-19

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

Screenshot of file structure and statements

CodePudding user response:

The namespace provided in the file DoughnutService.cs is probably not correct. Change that to RazorPagesDoughnuts.Services and check.

CodePudding user response:

In C# using statements are not based on file structure, but rather on namespaces. If there aren't any files with the statement namespace 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.

  • Related