Blazor cannot find the InteractiveServer render mode
Your error
error CS0103: The name 'InteractiveServer' does not exist in the current context3 more lines it can showFix it fast
Most common cause, 1 of 3_Imports.razor has no static using for RenderMode
Add the static using to the imports file of the project, then rebuild.
@* Components/_Imports.razor *@
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@* or, without the import, in one component *@
@rendermode RenderMode.InteractiveServerShort answer
In a Blazor Web App, The name 'InteractiveServer' does not exist in the current context (CS0103) means the project's _Imports.razor lacks @using static Microsoft.AspNetCore.Components.Web.RenderMode. Add that line, or write RenderMode.InteractiveServer in full. If it compiles but throws that required endpoints are not mapped, chain AddInteractiveServerRenderMode onto MapRazorComponents. Applies to .NET 8 through 11.
Which cause do you have?
Check two places at once: the RenderMode import in every _Imports.razor, and the render mode calls in Program.cs. A build error points to cause 1 or 2; an exception at page load points to cause 3.
grep -rn "Web.RenderMode" --include=_Imports.razor .
grep -rn "AddInteractive" --include=Program.cs .Then find the line you see in this list and open its fix:
- 1_Imports.razor has no static using for RenderMode
The build stops with CS0103 on InteractiveServer, and the first grep prints nothing for the project that holds the component - 2The component sits in the .Client project, whose imports file differs
Pages in the server project compile, but a component in the .Client (WebAssembly) project or another component project gets CS0103 on InteractiveWebAssembly or InteractiveAuto - 3Program.cs never maps the interactive render mode
The app builds, and the page throws InvalidOperationException saying the required endpoints are not mapped on the server
What does the error look like?
error CS0103: The name 'InteractiveServer' does not exist in the current contextThe name 'InteractiveWebAssembly' does not exist in the current contextInvalidOperationException: A component of type '...' has render mode 'InteractiveServerRenderMode', but the required endpoints are not mapped on the server.When calling 'MapRazorComponents', add a call to 'AddInteractiveServerRenderMode'.
Cause 1 of 3
_Imports.razor has no static using for RenderMode
You seeThe build stops with CS0103 on InteractiveServer, and the first grep prints nothing for the project that holds the component
Check
CS0103 on InteractiveServer means the compiler sees a bare name it cannot resolve. The short names live on the static RenderMode class. New Blazor Web App templates import it in Components/_Imports.razor, but apps moved up from Blazor Server on .NET 7 or built by hand often lack the line.
cat Components/_Imports.razorFix
Add the static using to the imports file of the project, then rebuild. A single component can instead use the full form RenderMode.InteractiveServer.
@* Components/_Imports.razor *@
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@* or, without the import, in one component *@
@rendermode RenderMode.InteractiveServerVerify
dotnet build finishes with no CS0103 error for the render mode name.
dotnet buildConfirmed by learn.microsoft.com
Cause 2 of 3
The component sits in the .Client project, whose imports file differs
You seePages in the server project compile, but a component in the .Client (WebAssembly) project or another component project gets CS0103 on InteractiveWebAssembly or InteractiveAuto
Check
Each project has its own _Imports.razor, and an import in the server project does not reach the .Client project. Microsoft's .NET 8 migration steps add the RenderMode import to the .Client project's file and copy that file into the server project.
ls */_Imports.razor */Components/_Imports.razor 2>/dev/nullFix
Add the same static using to the _Imports.razor of the project that owns the failing component. Keep both imports files in step when you add new shared usings.
@* MyApp.Client/_Imports.razor *@
@using static Microsoft.AspNetCore.Components.Web.RenderModeVerify
The .Client project builds on its own with no CS0103 line.
dotnet build MyApp.Client/MyApp.Client.csprojConfirmed by learn.microsoft.com
Cause 3 of 3
Program.cs never maps the interactive render mode
You seeThe app builds, and the page throws InvalidOperationException saying the required endpoints are not mapped on the server
Check
Naming a render mode is not enough. The app must add the interactive component services and chain the matching render mode onto MapRazorComponents. ASP.NET Core checks this when it renders the component and names the missing call in the exception.
grep -n -A3 "AddRazorComponents\|MapRazorComponents" Program.csFix
Register the services and the endpoints for each interactive mode the app uses. Add the WebAssembly pair as well if any component uses InteractiveWebAssembly or InteractiveAuto.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();Verify
The page loads without the exception and buttons respond, which shows the interactive circuit is up.
dotnet runConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- After moving a Blazor Server app to a Blazor Web App, diff every _Imports.razor and Program.cs against a freshly generated template of the same .NET version.
- Keep one shared list of usings for the server and .Client projects, and update both in the same commit.
- Add a build step in CI that compiles the .Client project too, so a missing import fails the pipeline, not a developer's machine.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Raheeb, Loade Driver, Dhero.