{"record":{"id":"4be9490448a8e91b","repo":"LykosAI/StabilityMatrix","slug":"dockcontrol-not-found","errorCode":null,"errorMessage":"DockControl not found","messagePattern":"DockControl not found","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Controls/Dock/DockUserControlBase.cs","lineNumber":37,"sourceCode":"/// Base for Dock controls\n/// Expects a <see cref=\"DockControl\"/> named \"Dock\" in the XAML\n/// </summary>\npublic abstract class DockUserControlBase : DropTargetUserControlBase\n{\n    private DockControl? baseDock;\n    private readonly DockSerializer dockSerializer = new(typeof(AvaloniaList<>));\n    private readonly DockState dockState = new();\n    private readonly DockState initialDockState = new();\n    private IDock? initialLayout;\n\n    /// <inheritdoc />\n    protected override void OnApplyTemplate(TemplateAppliedEventArgs e)\n    {\n        base.OnApplyTemplate(e);\n\n        baseDock =\n            this.FindControl<DockControl>(\"Dock\")\n            ?? throw new NullReferenceException(\"DockControl not found\");\n\n        if (baseDock.Layout is { } layout)\n        {\n            dockState.Save(layout);\n            initialDockState.Save(layout);\n            initialLayout = layout;\n            // Dispatcher.UIThread.Post(() => dockState.Save(layout), DispatcherPriority.Background);\n        }\n    }\n\n    /// <inheritdoc />\n    protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)\n    {\n        base.OnAttachedToVisualTree(e);\n\n        // Attach handlers for view state saving and loading\n        if (DataContext is InferenceTabViewModelBase vm)\n        {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Controls/Dock/DockUserControlBase.cs#L19-L55","documentation":"DockUserControlBase.OnApplyTemplate resolves the template child named 'Dock' as a DockControl via FindControl. If the applied control template lacks a DockControl named 'Dock', a NullReferenceException('DockControl not found') is thrown, aborting template application and breaking the control's dock layout setup.","triggerScenarios":"The control's XAML ControlTemplate does not include <DockControl Name=\"Dock\"/>, the template is not applied (control used without its default style), or FindControl returns null because the part was renamed or nested in another name scope.","commonSituations":"Custom restyle of the control that drops the required Dock part; using the control with a theme that doesn't ship its template; renaming the x:Name in the template during refactoring.","solutions":["Add <controls:DockControl x:Name=\"Dock\"/> to the control's ControlTemplate","Ensure the control's default style/template is actually applied (Themes included, StyleKey matches)","Keep the template part name 'Dock' unchanged and use TemplatePart attributes for documentation","Check that OnApplyTemplate is firing (template attached) rather than FindControl returning null from a different namescope"],"exampleFix":"// before (template missing part)\n<ControlTemplate><ContentPresenter/></ControlTemplate>\n// after\n<ControlTemplate>\n  <dock:DockControl x:Name=\"Dock\"/>\n</ControlTemplate>","handlingStrategy":"validation","validationCode":"var dock = this.FindControl<DockControl>(\"Dock\");\nif (dock is null) { Log.Error(\"Template missing Dock part\"); return; }","typeGuard":"bool HasDockPart(TemplatedControl c) => c.Template != null && c.FindControl<DockControl>(\"Dock\") != null;","tryCatchPattern":"try { baseDock = this.FindControl<DockControl>(\"Dock\")!; }\ncatch (NullReferenceException ex) { Log.Error(ex, \"Dock template part missing\"); }","preventionTips":["Keep template part names aligned with [TemplatePart] declarations","Never override the control template without including all required named parts","Test custom styles against template-applied behavior"],"tags":["avalonia","control-template","dock","null-reference"],"backgroundTag":"resource-not-found","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}