There are several reasons for this error message, especially after upgrading .Net version of project.
File names may be different
If you are using ‘code behind’ pattern (keeping your codes in another .cs file), your Mypage.razor
and mypage.razor.cs
file names must be same and first letter of files must be uppercase.
If file names are like the above (Mypage and mypage), it will give error. It must be i.e. MyPage.razor and MyPage.razor.cs
Your page should be inherited from ComponentBase
It can be like :public
partial
class
MyPage : ComponentBase {
in .razor.cs file or @inherits ComponentBase
in .razor file.
Your page and code files must be in same directory.