Skip to content

Improve diagnostics for Interactive Server component activation failures caused by missing DI services - #69693

Merged
kotlarmilos merged 13 commits into
dotnet:mainfrom
BrundhaVelusamy:52598-_ErrorHandling
Nov 20, 2026
Merged

kotlarmilos merged 13 commits into
dotnet:mainfrom
BrundhaVelusamy:52598-_ErrorHandling

Conversation

@BrundhaVelusamy

@BrundhaVelusamy BrundhaVelusamy commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a non-prerendered Interactive Server component injects a service that is not registered, component activation fails during the initial interactive render and the circuit is terminated.

Although the underlying exception is correctly thrown and handled by the circuit error pipeline, the root cause is not easily discoverable from default server logs. Developers typically see the standard Blazor fatal-error UI in the browser, but the actionable exception explaining the missing service registration is difficult to identify without additional diagnostics.

This change improves diagnostics for initial root component activation failures by ensuring that the original activation exception is surfaced through a dedicated error log entry, making configuration and dependency injection issues easier to identify.

Changes

  • Improved diagnostics for initial root component activation failures.
  • Added dedicated error logging that preserves the original activation exception.
  • Added regression coverage for component activation failure scenarios.
  • Preserved existing circuit behavior, browser error UI, exception handling flow, and DetailedErrors behavior.

Scenario

@rendermode @(new InteractiveServerRenderMode(prerender: false))
@inject WeatherForecastService ForecastService

When WeatherForecastService is not registered:

  • The component fails to activate during circuit startup.
  • The circuit displays the existing Blazor fatal-error UI and terminates.
  • The original InvalidOperationException is now emitted in normal server logs at Error level, making the root cause immediately visible.

Behavioral Impact

This change does not modify:

  • Circuit termination behavior
  • Exception propagation semantics
  • Browser error UI
  • CircuitOptions.DetailedErrors behavior
  • Security characteristics of exception disclosure

The change only improves the visibility of root component activation failures in server logs.

Validation

  • Reproduced the reported missing DI service scenario.
  • Verified that the activation failure is surfaced through error logging with the original exception details preserved.
  • Added regression tests covering activation failure diagnostics.
  • Validated existing behavior remains unchanged outside of the improved logging experience.

Fixes: #52598

Output

Before:
image

After:

image

@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Oct 7, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 7, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @BrundhaVelusamy. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@BrundhaVelusamy
BrundhaVelusamy marked this pull request as ready for review October 8, 2026 11:49
@BrundhaVelusamy
BrundhaVelusamy requested a review from a team as a code owner October 8, 2026 11:49
Copilot AI balanced review requested due to automatic review settings October 8, 2026 11:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused logging changes preserve existing behavior and have appropriate regression coverage.

0 open findings

What changed in this PR

Improves Blazor Interactive Server diagnostics for circuit startup and root-component activation failures.

Changes:

  • Promotes relevant circuit failure logs from Debug to Error.
  • Adds logging and missing-service activation regression coverage.
  • Allows test circuit hosts to receive a logger.
File Description
CircuitHost.cs Raises failure log levels.
CircuitHostTest.cs Verifies error logging and exception propagation.
TestCircuitHost.cs Supports injecting test loggers.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Oct 15, 2026
@PureWeen

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source-only review of frozen head 3a579bae63c05935d03a5f8b336fc4c8e69a2389 found one new P2 diagnostics issue: circuit-handler failures can now produce duplicate Error records.

Both routed guides completed: docs/CrossCuttingGuidance.md and docs/BlazorComponentsGuidance.md. No true-positive duplicate was present in prepared feedback, and no candidates remain unresolved. The earlier review at pullrequestreview-5456140719 reported no findings.

Provenance: immutable version-2 bundle; merge base 1e4a69d0aba443940f4d28dae1f8dec8a7f6310f; base tip and reviewer guidance commit 12e90ca7cb7334d40f2dbf9752ee4d42f33628a7. Product source, exact overloads, and full error paths were read from the frozen bundle. No materially changed area lacked a routed guide.

Test boundary: source analysis only; PR code, tests, CI, browser workflows, and samples were not executed. Security assessment was excluded by bundle policy. Feedback posted after bundle preparation and runtime behavior beyond the frozen source were not observable.

Generated by ASP.NET Core Pull Request Review for #69693 · copilot · gpt56 · 390.3 AIC · ⌖ 19.7 AIC · ⊞ 18.8K
Comment /review to run again

@PureWeen

Copy link
Copy Markdown
Member

Keep invalid client-state transitions below Error

Could we separate client-state validation failures from activation failures before promoting the shared UpdateRootComponentsFailed event to Error?

On an established legacy Blazor Server circuit started with nonempty component descriptors, an UpdateRootComponents invocation containing {"batchId":1,"operations":[]} and an empty application-state string passes deserialization. The host then rejects the unsupported state transition at its Descriptors.Count > 0 guard, before component activation. This change promotes that rejection from Debug to Error.

The existing area logging guidance explicitly requires lower severity for invalid client-state transitions and says not to promote a catch-all shared with client-input failures. Please keep those rejections at lower severity while retaining Error for genuine activation/configuration failures.

This is a source-traced invalid-client-input case, not a live-connection reproduction or a claim that the stock client normally emits this sequence.

Prepared by GitHub Copilot in collaboration with a human reviewer.

@BrundhaVelusamy

Copy link
Copy Markdown
Contributor Author

Keep invalid client-state transitions below Error

Could we separate client-state validation failures from activation failures before promoting the shared UpdateRootComponentsFailed event to Error?

On an established legacy Blazor Server circuit started with nonempty component descriptors, an UpdateRootComponents invocation containing {"batchId":1,"operations":[]} and an empty application-state string passes deserialization. The host then rejects the unsupported state transition at its Descriptors.Count > 0 guard, before component activation. This change promotes that rejection from Debug to Error.

The existing area logging guidance explicitly requires lower severity for invalid client-state transitions and says not to promote a catch-all shared with client-input failures. Please keep those rejections at lower severity while retaining Error for genuine activation/configuration failures.

This is a source-traced invalid-client-input case, not a live-connection reproduction or a claim that the stock client normally emits this sequence.

Prepared by GitHub Copilot in collaboration with a human reviewer.

Hi @PureWeen,

Addressed. I kept the shared UpdateRootComponentsFailed event at Debug and introduced a dedicated RootComponentInitializationFailed event at Error around initial root-component rendering/activation only.

Invalid client-state transitions, including invoking UpdateRootComponents on a legacy circuit initialized with nonempty descriptors, therefore remain below Error. I also added regression coverage asserting that this transition produces zero error-level records.

@PureWeen

Copy link
Copy Markdown
Member

/review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Operation-limit rejections are incorrectly logged as Error-level initialization failures rather than Debug-level rejected input, and the new test does not exercise the affected catch block.

1 open issue

Review effort: Balanced

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source-only review of frozen head 82958d2902aaa3a79630fdc13ea8c668fdca72a1 found one verified P3 diagnostics issue and surfaced one P2 concern as unresolved because the required logger-failure contract is unavailable.

Both routed guides completed: docs/CrossCuttingGuidance.md and docs/BlazorComponentsGuidance.md. The verified issue is that the first root-update catch also covers inbound middleware, so a middleware failure before next is falsely logged as root-component initialization failure. The unresolved concern is that a throwing logger can replace the original activation exception, but the frozen evidence does not establish a binding policy requiring suppression or preservation in that scenario.

Existing feedback did not duplicate either item. Earlier feedback about catch-all Error promotion and duplicate circuit-handler Error records is addressed in this frozen head: the shared wrapper events remain Debug, lifecycle failures occur outside the new catch, and source-level regression tests cover those paths. No materially changed area lacked a routed guide.

Provenance: immutable version-2 bundle; merge base b38e2847d9cda5fbba26177354ed11ede3f7dbfe; base tip and reviewer-guidance commit 49147673007a4b1d676694e2c5f85b83ad76c36f. Product source, public hook contracts, exact pipeline ordering, and old/new failure paths were read from the frozen bundle. The review is source-only: PR code, tests, CI, browser workflows, and samples were not executed. Security assessment was excluded by bundle policy. Feedback posted after preparation, external ILogger contracts, pointer targets, and runtime behavior beyond frozen tracked source were not observable.

Generated by ASP.NET Core Pull Request Review for #69693 · copilot · gpt56 · 231.6 AIC · ⌖ 8.59 AIC · ⊞ 20.1K
Comment /review to run again

@PureWeen

Copy link
Copy Markdown
Member

/review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Persisted-circuit resume can accept a marker without a key, causing rejected input to be logged as an Error-level initialization failure instead of a Debug-only diagnostic.

1 open issue
1 resolved since last review

Review effort: Balanced

@PureWeen

Copy link
Copy Markdown
Member

All three local arms reviewed 6c9f5803a0a1bf1c759f8f29eebe8d3937365ec6 and found no new issues to post. The existing persisted-resume marker-key comment remains unresolved, so agent-reviewed-needs-changes stays in place. I did not repeat it inline.

Informational: The logger-failure concern still lacks a binding failure-policy contract. Its GitHub thread is resolved. This uncertainty does not block approval.

At CircuitHost.cs:856, later-batch activation failures predate this change and fall outside the stated initial-activation scope. The arms discarded that incomplete-fix claim before candidate verification.

Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block agent-reviewed-approved.

Other discarded checks: Duplicate Error logs, swallowed activation exceptions, restoration-order changes, operation-limit and pre-next middleware misclassification, WebAssembly/public API breaks, event-ID collisions, nullable warnings, and vacuous tests.

Untested coverage gaps: No restore-path test covers the missing marker key. The arms also note no direct coverage of the RenderAsync catch. These are coverage observations, not additional findings.

Validation boundary: All three local arms reviewed frozen source only. They did not run target code, builds, tests, or browsers.

Human-directed and GitHub Copilot-generated.

@BrundhaVelusamy

Copy link
Copy Markdown
Contributor Author

All three local arms reviewed 6c9f5803a0a1bf1c759f8f29eebe8d3937365ec6 and found no new issues to post. The existing persisted-resume marker-key comment remains unresolved, so agent-reviewed-needs-changes stays in place. I did not repeat it inline.

Informational: The logger-failure concern still lacks a binding failure-policy contract. Its GitHub thread is resolved. This uncertainty does not block approval.

At CircuitHost.cs:856, later-batch activation failures predate this change and fall outside the stated initial-activation scope. The arms discarded that incomplete-fix claim before candidate verification.

Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block agent-reviewed-approved.

Other discarded checks: Duplicate Error logs, swallowed activation exceptions, restoration-order changes, operation-limit and pre-next middleware misclassification, WebAssembly/public API breaks, event-ID collisions, nullable warnings, and vacuous tests.

Untested coverage gaps: No restore-path test covers the missing marker key. The arms also note no direct coverage of the RenderAsync catch. These are coverage observations, not additional findings.

Validation boundary: All three local arms reviewed frozen source only. They did not run target code, builds, tests, or browsers.

Human-directed and GitHub Copilot-generated.

@PureWeen, The persisted-resume marker-key concern has been addressed.

Marker-key validation now occurs before the component activation error boundary. A resumed operation with a missing marker key therefore preserves the existing InvalidOperationException and circuit error flow, but is no longer reported as RootComponentInitializationFailed at Error.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the root-component initialization diagnostics change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@PureWeen

Copy link
Copy Markdown
Member

/review

@PureWeen

Copy link
Copy Markdown
Member

Copilot's local review panel found no issues to raise at this commit.

All three local arms completed their reviews of 60debe9cf37af4f0767f8918b5f2fc25b75e0e97. The persisted-resume marker-key feedback is addressed, and no prior agent review threads remain unresolved.

Informational [DISCARDED]: One arm flagged the new // Arrange, // Act, and // Assert comments in CircuitHostTest.cs at lines 1142, 1150, and 1156. The required independent checks split: one confirmed the literal instruction mismatch; the other rejected it as a style-only item with no material effect. It did not meet the publication threshold and is not an inline finding.

Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block agent-reviewed-approved.

Other discarded/unresolved checks: The later-batch activation and logger-policy concerns, along with routine negative checks, duplicate the previous panel note and are not reposted as findings.

Untested coverage gaps: The previously noted lack of a direct RenderAsync-catch test remains a nonblocking coverage observation. Later-batch activation remains outside this PR's initial-activation scope.

Validation boundary: All three local arms reviewed frozen source only. They did not run target code, builds, tests, or browsers.

Human-directed and GitHub Copilot-generated.

@kotlarmilos
kotlarmilos merged commit cf1e24e into dotnet:main Nov 20, 2026
38 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

✅ No documentation PR was created.

Confidence that documentation is needed: 10%

Confident no docs needed: logging-only diagnostics improvement with tests; no public or documented behavior change.

Documentation surfaces considered

  • Conceptual article: Not required — Only adds an error log entry; no public API, config, or documented behavior changes; no signals detected.
  • Migration guidance: Not required — No upgrade action needed.
  • Breaking change: Not required — No compatibility impact; circuit behavior unchanged.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 60debe9c Deployed Nov 20, 2026 by kotlarmilos via conclusion #423
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-reviewed-approved area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blank page and no error when injecting undefined service in InteractiveServer

5 participants