{"record":{"id":"783ea0b95b21db7a","repo":"tui-cs/Terminal.Gui","slug":"adornment-must-be-of-type-border","errorCode":null,"errorMessage":"Adornment must be of type Border","messagePattern":"Adornment must be of type Border","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/ViewBase/Adornment/BorderView.cs","lineNumber":219,"sourceCode":"                              Math.Max (0,\n                                        screenRect.Width\n                                        - Math.Max (0, Math.Max (0, Adornment.Thickness.Left - 1) + Math.Max (0, Adornment.Thickness.Right - 1))),\n                              Math.Max (0,\n                                        screenRect.Height\n                                        - Math.Max (0, Math.Max (0, Adornment.Thickness.Top - 1) + Math.Max (0, Adornment.Thickness.Bottom - 1))));\n    }\n\n    /// <inheritdoc/>\n    protected override bool OnDrawingContent (DrawContext? context)\n    {\n        if (Adornment is null || Adornment.Thickness == Thickness.Empty)\n        {\n            return true;\n        }\n\n        if (Adornment is not Border border)\n        {\n            throw new InvalidOperationException (\"Adornment must be of type Border\");\n        }\n\n        // Tab mode: completely separate codepath with edge-based border positioning\n        if (border.Settings.FastHasFlags (BorderSettings.Tab))\n        {\n            return DrawTabBorder (border);\n        }\n\n        return DrawLegacyBorder (context, border);\n    }\n\n    /// <summary>\n    ///     INTERNAL: Draws the border and title when <see cref=\"BorderSettings.Tab\"/> is not set.\n    ///     Retained for backward compatibility and for use when tab mode is not desired.\n    /// </summary>\n    private bool DrawLegacyBorder (DrawContext? context, Border border)\n    {\n        Rectangle screenBounds = ViewportToScreen (Viewport);","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/ViewBase/Adornment/BorderView.cs#L201-L237","documentation":"This error is thrown by BorderView.OnDrawingContent() when the Adornment associated with the BorderView is not of type Border. BorderView is a specialized AdornmentView whose rendering logic (DrawTabBorder, DrawLegacyBorder) assumes its Adornment is specifically a Border, not a generic Margin or Padding. This invariant is established during view construction and should never be violated in normal use; hitting it indicates a programming error in view construction or adornment assignment.","triggerScenarios":"Thrown at BorderView.cs:219 when OnDrawingContent is called and Adornment is not null, has non-empty Thickness, but is not castable to Border. This implies a BorderView was associated with the wrong type of adornment, which should be structurally impossible through normal API usage.","commonSituations":"Custom view construction code that manually assigns the wrong adornment type to a BorderView, reflection-based test tooling that reassigns adornments, subclassing AdornmentView/BorderView incorrectly, or internal bugs during view composition.","solutions":["Ensure BorderView is only used with Border adornments -- this is enforced by the normal View API; do not bypass it.","If subclassing, preserve the Border type constraint on the Adornment property.","If using reflection or test tooling to manipulate adornments, verify type compatibility before assignment.","Check for any code that creates a BorderView and manually sets its Adornment to a non-Border adornment."],"exampleFix":"// before -- assigning wrong adornment type to BorderView\nborderView.GetType().GetProperty(\"Adornment\").SetValue(borderView, new Margin(...));\n\n// after -- BorderView only works with Border\nview.Border = new Border { Thickness = new Thickness(1) };\n// The BorderView is created internally and correctly associated","handlingStrategy":"type-guard","validationCode":"// Ensure BorderView is only used with Border adornments\nif (adornment is Border) { /* safe to use with BorderView */ }","typeGuard":"bool IsValidBorderAdornment(Adornment a) => a is Border;","tryCatchPattern":"// OnDrawingContent is called internally; no caller-side catch is typical.\n// This indicates a construction bug -- fix the adornment assignment.","preventionTips":["Always create borders via view.Border = new Border { ... }, which correctly associates BorderView with Border.","Do not manually reassign Adornment on a BorderView via reflection.","When subclassing BorderView, preserve the Border type constraint.","If using test tooling, verify adornment type compatibility before drawing."],"tags":["adornment","borderview","viewbase","rendering","invariant"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}