Home > OS >  Deleted files gives CS0246 compiler error in VS2022
Deleted files gives CS0246 compiler error in VS2022

Time:11-03

I've added 3 default Blazor projects to my solution.

  1. Blazor WebAssembly1
  2. Blazor WebAsssembly2
  3. Blazor Server

The first WebAssembly project is converted to a razor library in order to share code between server and webassembly projects. I also deleted the default pages like FetchData.razor and such.

On compilation I still get compile error on this (the app runs fine though), and I can't seem to resolve them. I've search through the entire solution but can't find any of the files that results in the compile errors.

How to locate the reason for the errors and remove the references? The files are deleted from the project.

Example of compiler error: CS0246 The type or namepace 'WeatherForecastService' could not be found (are you missing a using directive or an assembly reference?)

CodePudding user response:

The errors in FetchData indicate a problem with the using statements. Try to check if you have global using, try to remove and declare explicit in the razor page. Check your CSPROJ and verify the project type, in the RCL the type must be: <Project Sdk="Microsoft.NET.Sdk.Razor">

In the RCL you haven't a Program/App structure, you have only components and wwwroot elements. My RCL is composed as follow:

RCL project

I have also a _Imports.razor with:

@using Microsoft.AspNetCore.Components.Web
...

CodePudding user response:

The issue resolved itself when I restarted Visual Studio. Sorry for the wild goose chase

  • Related