tui-cs/Terminal.Gui · error · InvalidOperationException

AdornmentView can only render to their Parent or Parent's Su

Error message

AdornmentView can only render to their Parent or Parent's Superview.

What it means

This error is thrown by AdornmentView.SuperViewRendersLineCanvas setter because AdornmentViews are designed to render exclusively to their parent's or parent's SuperView's LineCanvas, never to their own. Setting this property to true would imply the AdornmentView maintains its own LineCanvas for rendering, which contradicts its architectural role. The getter always returns false to signal this.

Source

Thrown at Terminal.Gui/ViewBase/Adornment/AdornmentView.cs:176

        return true;
    }

    /// <inheritdoc/>
    protected override bool OnDrawingText () => Adornment is null || Adornment.Thickness == Thickness.Empty;

    /// <inheritdoc/>
    protected override bool OnDrawingSubViews () => Adornment is null || Adornment.Thickness == Thickness.Empty;

    /// <summary>Does nothing for AdornmentView.</summary>
    protected override bool OnRenderingLineCanvas () => true;

    /// <summary>
    ///     AdornmentViews only render to their <see cref="IAdornment.Parent"/>'s or Parent's SuperView's LineCanvas.
    /// </summary>
    public override bool SuperViewRendersLineCanvas
    {
        get => false;
        set => throw new InvalidOperationException (@"AdornmentView can only render to their Parent or Parent's Superview.");
    }

    /// <summary>
    ///     Indicates whether the specified Parent's SuperView-relative coordinates are within the Adornment's
    ///     <see cref="Thickness"/>.
    /// </summary>
    public override bool Contains (in Point location)
    {
        View? parentOrSuperView = Adornment?.Parent;

        if (parentOrSuperView is null)
        {
            parentOrSuperView = SuperView;

            if (parentOrSuperView is null)
            {
                return false;
            }

View on GitHub (pinned to 2e47b11478)

Solutions

  1. Do not set SuperViewRendersLineCanvas on AdornmentView -- it is architecturally fixed at false.
  2. In generic view-processing code, check 'if (view is AdornmentView) continue;' before setting this property.
  3. If this occurs during deserialization, exclude the property via [JsonIgnore] or similar for AdornmentView.
  4. AdornmentViews always render through their parent's LineCanvas; this cannot be changed.

Example fix

// before -- generic property setter hits the invariant
foreach (var prop in typeof(View).GetProperties()) { prop.SetValue(view, defaultValue); }

// after -- skip AdornmentView-specific properties
if (view is AdornmentView) continue;
prop.SetValue(view, defaultValue);
Defensive patterns

Strategy: type-guard

Validate before calling

// Before setting SuperViewRendersLineCanvas, check the view type
if (view is not AdornmentView) { view.SuperViewRendersLineCanvas = true; }

Type guard

bool CanSetSuperViewRendersLineCanvas(View v) => v is not AdornmentView;

Try / catch

try { view.SuperViewRendersLineCanvas = value; }
catch (InvalidOperationException ex) when (ex.Message.Contains("AdornmentView can only render"))
{ /* AdornmentView always renders to parent LineCanvas; skip */ }

Prevention

When it happens

Trigger: Thrown at AdornmentView.cs:176 when any code attempts to set the SuperViewRendersLineCanvas property on an AdornmentView. This could happen via generic property-setting code, serialization/deserialization frameworks, or test infrastructure that iterates over all view properties.

Common situations: Generic view-testing tooling (like AllViewsTester) that sets every property on every view type, deserialization that restores all properties, custom rendering code that attempts to control LineCanvas behavior generically, or copy/clone utilities that replicate all properties.

Related errors


AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13). Data as JSON: /api/errors/572612a60fab8995. Report an issue: GitHub.