Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

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 show

Fix 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.

Fix
@* Components/_Imports.razor *@
@using static Microsoft.AspNetCore.Components.Web.RenderMode

@* or, without the import, in one component *@
@rendermode RenderMode.InteractiveServer
Did this fix it?
Full steps for this cause: check, fix, verify

Short 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.

  • Applies to .NET 11.0.0, .NET 10.0.15 (LTS), Blazor Web App template, .NET 8 and later
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
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. 1_Imports.razor has no static using for RenderModeThe build stops with CS0103 on InteractiveServer, and the first grep prints nothing for the project that holds the component
  2. 2The component sits in the .Client project, whose imports file differsPages in the server project compile, but a component in the .Client (WebAssembly) project or another component project gets CS0103 on InteractiveWebAssembly or InteractiveAuto
  3. 3Program.cs never maps the interactive render modeThe 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 context
  • The name 'InteractiveWebAssembly' does not exist in the current context
  • InvalidOperationException: 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.

Check
cat Components/_Imports.razor

Fix

Add the static using to the imports file of the project, then rebuild. A single component can instead use the full form RenderMode.InteractiveServer.

Fix
@* Components/_Imports.razor *@
@using static Microsoft.AspNetCore.Components.Web.RenderMode

@* or, without the import, in one component *@
@rendermode RenderMode.InteractiveServer

Verify

dotnet build finishes with no CS0103 error for the render mode name.

Verify
dotnet build

Confirmed by learn.microsoft.com

Did this fix it?

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.

Check
ls */_Imports.razor */Components/_Imports.razor 2>/dev/null

Fix

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.

Fix
@* MyApp.Client/_Imports.razor *@
@using static Microsoft.AspNetCore.Components.Web.RenderMode

Verify

The .Client project builds on its own with no CS0103 line.

Verify
dotnet build MyApp.Client/MyApp.Client.csproj

Confirmed by learn.microsoft.com

Did this fix it?

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.

Check
grep -n -A3 "AddRazorComponents\|MapRazorComponents" Program.cs

Fix

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.

Fix
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.

Verify
dotnet run

Confirmed by raw.githubusercontent.com

Did this fix it?

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.