Aspnetcore: Blazor component: The name 'page' does not exist in the current context

Created on 18 Jun 2019  路  6Comments  路  Source: dotnet/aspnetcore

Visual Studio 2019 16.2.0 Preview 2.0
.net core 3.0.100-preview6-012264

I have a Blazor client-side project in which I've created a number of components. The most recent component (a .razor file, like the others) I've added will not recognize the @page and @code directives. I'm not sure what the difference is between this component and the previous ones I've added. I've only used the original Shared and Pages folders. It doesn't matter which folder I attempt to make the new component in. The result is the same.

The components that I have added previously continue to work as expected. Only new ones exhibit the problem. The application still builds and runs, but the new components exhibiting this problem do not render at runtime.

It seems to coincide with a new error in the Error List:
"'Template.ExecuteAsync()': no suitable method found to override"

Below are screenshots of the errors for context:
image

image

Most helpful comment

For me unloading and reloading the project fixed it.

All 6 comments

It seems this is a similar problem to issue number 316 in the original aspnet/Blazor repository (https://github.com/aspnet/Blazor/issues/316). However, the issue only happens if a Watch Include directive is present in the .csproj file:

  <ItemGroup>
    <Watch Include="**\*.razor" />
  </ItemGroup>

I've been using this to automatically build with dotnet watch run. If the Watch Include directive is in the csproj file, the following items are generated in the .csproj file when adding a razor file to the project. These items apparently block the component from being compiled with the project.

  <ItemGroup>
    <Content Remove="Pages\Component.razor" />
  </ItemGroup>

  <ItemGroup>
    <Watch Remove="Pages\Component.razor" />
  </ItemGroup>

  <ItemGroup>
    <None Include="Pages\Component.razor" />
  </ItemGroup> 

If the Watch Include directive is removed, the extra items are not added to the .csproj file and everything works normally.

This may be the expected behavior, it's just a little inconvenient.

If anyone else finds themselves here, I was having this issue when I hadn't yet saved the solution file that was created for me by VS 2019 Preview. After saving ToDoList.sln on close of VS, I no longer had these issues.

If anyone else finds themselves here, I was having this issue when I hadn't yet saved the solution file that was created for me by VS 2019 Preview. After saving ToDoList.sln on close of VS, I no longer had these issues.

Thank you, just happened to stumble across this issue as well.

For me unloading and reloading the project fixed it.

For me unloading and reloading the project fixed it.

This also worked for me but this issue still persits post .net core 3.0 release any idea of what actually causes this??

Seems as though the project file gets muddled up?

i am also having this problem, once again an unload + reload works

Was this page helpful?
0 / 5 - 0 ratings