{"record":{"id":"ecdb425d256eb3b2","repo":"stride3d/stride","slug":"gamewindow-should-have-either-a-swapchainpanel-or-a","errorCode":null,"errorMessage":"GameWindow should have either a SwapChainPanel or a CoreWindow","messagePattern":"GameWindow should have either a SwapChainPanel or a CoreWindow","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Games/WindowsStore/GameWindowUWP.cs","lineNumber":99,"sourceCode":"\n        public override Rectangle ClientBounds\n        {\n            get\n            {\n                if (swapChainPanel != null)\n                {\n                    return new Rectangle(0, 0, \n                        (int)(swapChainPanel.ActualWidth  * swapChainPanel.CompositionScaleX + 0.5f),\n                        (int)(swapChainPanel.ActualHeight * swapChainPanel.CompositionScaleY + 0.5f));\n\n                }\n\n                if (coreWindow != null)\n                {\n                    return new Rectangle((int)(coreWindow.Bounds.X), (int)(coreWindow.Bounds.Y), (int)(coreWindow.Bounds.Width), (int)(coreWindow.Bounds.Height));\n                }\n\n                throw new ArgumentException($\"{nameof(GameWindow)} should have either a {nameof(SwapChainPanel)} or a {nameof(CoreWindow)}\");\n            }\n        }\n\n        public override DisplayOrientation CurrentOrientation => DisplayOrientation.Default;\n\n        public override bool IsMinimized => false;\n        \n        public override bool Focused => focused;\n\n        private bool isMouseVisible;\n        private CoreCursor cursor;\n\n        public override bool IsMouseVisible\n        {\n            get\n            {\n                return isMouseVisible;\n            }","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Games/WindowsStore/GameWindowUWP.cs#L81-L117","documentation":"GameWindowUWP.ClientBounds requires either a SwapChainPanel or a CoreWindow to measure the window rectangle; when neither is present it throws an ArgumentException naming the missing components. On UWP the render target is hosted by one of these two XAML/Core objects, so a GameWindow without either has no defined client bounds.","triggerScenarios":"Accessing ClientBounds on a GameWindowUWP whose SwapChainPanel and CoreWindow are both null — e.g. the window was constructed but not yet bound to the XAML SwapChainPanel or activated CoreWindow, or queried during/after app suspension.","commonSituations":"Reading ClientBounds too early during UWP startup before panel binding, custom UWP hosting that never sets SwapChainPanel, or accessing bounds after CoreWindow activation was lost.","solutions":["Ensure the SwapChainPanel is assigned to the GameWindow before reading ClientBounds (wait for the XAML panel to load).","Defer bounds queries until after CoreWindow activation (WindowActivated/Loaded callbacks) rather than during construction.","Fix the hosting code so exactly one of SwapChainPanel/CoreWindow is provided when creating GameWindowUWP."],"exampleFix":"// before\nvar bounds = gameWindow.ClientBounds; // panel not yet assigned\n// after\nswapChainPanel.Loaded += (s, e) =>\n{\n    gameWindow.SwapChainPanel = swapChainPanel;\n    var bounds = gameWindow.ClientBounds;\n};","handlingStrategy":"validation","validationCode":"bool CanReadBounds(GameWindowUWP w) => w.SwapChainPanel != null || w.CoreWindow != null;\nvar bounds = CanReadBounds(gameWindow) ? gameWindow.ClientBounds : Rect.Empty;","typeGuard":"bool HasHostSurface(GameWindowUWP w) => w.SwapChainPanel != null || w.CoreWindow != null;","tryCatchPattern":"try { var b = gameWindow.ClientBounds; }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"SwapChainPanel\"))\n{\n    // wait for panel binding / CoreWindow activation, then retry\n}","preventionTips":["Bind the XAML SwapChainPanel to the GameWindow before any layout/bounds logic runs.","Query bounds only after CoreWindow activation or panel Loaded events.","In custom UWP hosts, guarantee exactly one host surface is provided."],"tags":["uwp","window","xaml","null-reference"],"backgroundTag":"missing-dependency","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}