Thursday, July 18, 2024

Razor component not found in razor page

 

This was a problem both with VS Code and Visual Studio 2022 (various updates)


There is somebody with the same problem on Stack Overflow but it is never explained why the "fix" worked

https://stackoverflow.com/questions/58527473/web-pages-shared-components-razor-component-not-found-in-razor-page


What happened in my case is that I right-clicked and asked to exclude a file from the project, renamed it, and added another file with the same name. This seems to have resulted in the following set of items in the .csproj Project file


  <ItemGroup>

    <Content Remove="Components\Pages\DeleteItem.razor" />

  </ItemGroup>


  <ItemGroup>

    <UpToDateCheckInput Remove="Components\Pages\DeleteItem.razor" />

  </ItemGroup>


  <ItemGroup>

    <_ContentIncludedByDefault Remove="Components\Pages\DeleteItem.razor" />

  </ItemGroup>


  <ItemGroup>

    <None Include="Components\Pages\DeleteItem.razor" />

  </ItemGroup>


When I removed these lines, everything compiled as intended