Debug Diagnostics

Trace where rendered component markup came from when you are debugging capture, replay, or composition behavior.

Why stack exists

The stack attribute is diagnostic instrumentation. It is not required for ordinary component rendering, but it gives BCL a precise Razor caller location when diagnostics are enabled.

Use stack="this.GetStack()" when you want rendered output to identify the page, component partial, and line that contributed to a specific fragment. The method uses caller information, so the location is captured at the Razor call site.

Source markup

Add stack information to the tag helper you are investigating.

aspnet

<bs-button stack="this.GetStack()" btn-style="Primary">Save</bs-button>
    

Normal output

When stack capture is disabled, the rendered HTML stays focused on the Bootstrap output.

html

<button class="btn btn-primary">Save</button>
    

Diagnostic output

When stack capture is enabled, the rendered output can include source provenance through data-stack-trace.

html

<button class="btn btn-primary" data-stack-trace="Buttons.cshtml:42">Save</button>
    

Composed components

The value becomes more useful when a component is replayed through one or more internal partials. In those cases, the stack can show both the component partial and the original page source.

html

<div class="toast-body" data-stack-trace="BootstrapToast.cshtml:20;Toasts.cshtml:44">
    Live toast with custom body content and actions.
</div>
    

When to use it

Reach for stack diagnostics when a captured child renders in the wrong place, appears more than once, loses attributes, or does not render at all. It is especially useful for components that split source markup into multiple rendered regions, such as cards, toasts, dropdowns, tab navigation, and modal content.

Documentation samples

Public component examples may omit diagnostic stack attributes so the main docs stay focused on component intent. This page documents the diagnostic layer explicitly for cases where exact provenance matters.