{"record":{"id":"5f77bd3028fcc901","repo":"tui-cs/Terminal.Gui","slug":"the-viewport-of-an-adornmentview-cannot-be-modifie","errorCode":null,"errorMessage":"The Viewport of an AdornmentView cannot be modified.","messagePattern":"The Viewport of an AdornmentView cannot be modified\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/ViewBase/Adornment/AdornmentView.cs","lineNumber":92,"sourceCode":"        scheme = _scheme ?? Adornment?.Parent?.GetScheme () ?? SchemeManager.GetScheme (Schemes.Base);\n\n        return true;\n    }\n\n    /// <inheritdoc/>\n    protected override bool OnSettingScheme (ValueChangingEventArgs<Scheme?> args)\n    {\n        Adornment?.Parent?.SetNeedsDraw ();\n        _scheme = args.NewValue;\n\n        return false;\n    }\n\n    /// <inheritdoc/>\n    public override Rectangle Viewport\n    {\n        get => base.Viewport;\n        set => throw new InvalidOperationException (@\"The Viewport of an AdornmentView cannot be modified.\");\n    }\n\n    /// <inheritdoc/>\n    public override Rectangle FrameToScreen ()\n    {\n        if (Adornment?.Parent is null)\n        {\n            // Support AllViewsTester where AdornmentView may be a SubView.\n            if (SuperView is null)\n            {\n                return Frame;\n            }\n\n            Point super = SuperView.ViewportToScreen (Frame.Location);\n\n            return new Rectangle (super, Frame.Size);\n        }\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/ViewBase/Adornment/AdornmentView.cs#L74-L110","documentation":"This error is thrown by AdornmentView.Viewport setter because AdornmentView derives its viewport from its parent's adornment (Border, Margin, Padding) thickness and cannot have its viewport set independently. AdornmentViews are internal infrastructure views that represent the visual area of adornments around a parent view. Allowing direct viewport modification would break the geometric relationship between the adornment and its parent.","triggerScenarios":"Thrown at AdornmentView.cs:92 when any code attempts to set the Viewport property on an AdornmentView instance. This could be via direct assignment (view.Viewport = new Rectangle(...)), layout code, or reflection-based serialization/deserialization that sets all properties.","commonSituations":"Deserialization frameworks that set all properties including Viewport, test helpers that generically configure views, custom layout code that treats AdornmentViews like regular views, or AllViewsTester-style tooling that iterates and sets properties on all view types.","solutions":["Do not set Viewport on AdornmentView instances -- their viewport is computed from the parent's adornment thickness.","If writing generic view-processing code, check for AdornmentView and skip the Viewport setter.","To change the effective area, modify the parent's adornment Thickness instead.","If this occurs during deserialization, add a [JsonIgnore] or equivalent to exclude Viewport from serialization on AdornmentView."],"exampleFix":"// before -- setting Viewport on an AdornmentView throws\nborderView.Viewport = new Rectangle(0, 0, 10, 5);\n\n// after -- modify the parent's border thickness instead\nview.Border.Thickness = new Thickness(1);","handlingStrategy":"type-guard","validationCode":"// Before setting Viewport, check if the view is an AdornmentView\nif (view is not AdornmentView) { view.Viewport = new Rectangle(0, 0, w, h); }","typeGuard":"bool IsNotAdornmentView(View v) => v is not AdornmentView;","tryCatchPattern":"try { view.Viewport = rect; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"AdornmentView\"))\n{ /* skip; AdornmentView viewport is computed from parent */ }","preventionTips":["Never set Viewport on AdornmentView -- modify the parent's adornment Thickness instead.","In generic view-processing code, check for AdornmentView and skip the Viewport setter.","Exclude Viewport from serialization on AdornmentView subclasses.","AdornmentView viewport is always derived; treat it as read-only."],"tags":["adornment","viewbase","layout","viewport","invariant"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}