skip to Main Content

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

2

Answers


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

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search