skip to Main Content

Not really sure how to even categorize this as I wouldn’t assume it is an assembly reference.

Been building a razor pages app .Net 6.0 and everything has been fine. Published to Azure last week to get feedback and came back today to find the project won’t build.

I receive this error for every one of my view files

CS0234  The type or namespace name 'Pages' does not exist in the namespace
'Timesheet.Pages.Timesheet' (are you missing an assembly reference?)

No idea what the problem is, Pages folder definitely still exists and any file in a subfolder shows the correct path in the error message but all say Pages does not exist. I even added a test razor page with VS by right clicking the pages folder and the generated view file shows the same error.

Solution has 2 projects

Solution – Timesheet

Project 1 (Class Library) – Data Access

Project 2 (ASP.Net Web App) – Timesheet

I am not sure if it makes a difference but in the error message for all views not currently open in VS the file mentioned is actually the view file with the extension cshtml.g.cs which to me sounds like a virtual code behind.

So if test.cshtml is not open the error is for file test.cshtml.g.cs whereas if the file was open it would be for test.cshtml. All of the errors are reported on line 2 which is the model declaration such as
@model Timesheet.Pages.TestModel

2

Answers


  1. Chosen as BEST ANSWER

    I seem to have found a solution but I don't understand why it works and would be grateful for an explanation.

    Removing the solution name from the model declaration clears the error e.g. from above

    @model timesheet.Pages.TestModel Becomes @model Pages.TestModel

    and as it isn't in a subfolder it can even become @model TestModel similar to how index and privacy is declared.

    Could someone shed light on why now after publishing the solution to Azure, I now need to refactor all my view files to make this declaration change. I have other webapps not currently published to azure that have the solution name in the model declaration and they build fine. All use .Net 6.0 so I doubt it is a framework style but as mentioned above I have no explanation so would be grateful to anyone who could explain.


  2. I don’t know the ‘why’, but I believe this is probably the ‘what’ that caused it.

    I have the same issue. My page was named the same with the same solution name:

    Approval.Pages.Approval.

    When I don’t use ‘Approval’ as the name of the razor page, it works. I guess we shouldn’t name a page with the same name as the solution’s namespace.

    Even if I had sub-folders:
    Approval.Pages.Subfolder.Approval, it breaks the compilation.
    I just removed that page and create a new page with a slightly different name, eg. Approval.Pages.Subfolder.Approving

    Your ‘Timesheet.Pages.Timesheet’ – perhaps ‘Timesheet’ razor page should be named something else to stop this issue and you wouldn’t need to refactor.

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