{"record":{"id":"a0400baf9330544f","repo":"stride3d/stride","slug":"window-context-description-devicewindowhandle-context-not","errorCode":null,"errorMessage":"Window context [{Description.DeviceWindowHandle.Context}] not supported while creating SwapChain","messagePattern":"Window context \\[(.+?)\\] not supported while creating SwapChain","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D/SwapChainGraphicsPresenter.Direct3D.cs","lineNumber":674,"sourceCode":"                    if (result.IsFailure)\n                        result.Throw();\n\n                    // Finally, create the Swap-Chain\n                    var coreWindow = ToComPtr((IUnknown*) Marshal.GetIUnknownForObject(Description.DeviceWindowHandle.NativeWindow));\n\n                    result = dxgiFactory2.CreateSwapChainForCoreWindow(deviceAsIUnknown, coreWindow, in description, noOutput, ref swapChain);\n\n                    if (result.IsFailure)\n                        result.Throw();\n\n                    SafeRelease(ref coreWindow);\n                    SafeRelease(ref dxgiFactory2);\n                    SafeRelease(ref dxgiAdapter);\n                    SafeRelease(ref dxgiDevice2);\n                    break;\n                }\n                default:\n                    throw new NotSupportedException($\"Window context [{Description.DeviceWindowHandle.Context}] not supported while creating SwapChain\");\n            }\n\n            this.swapChain = swapChain;\n            swapChainVersion = GetLatestDxgiSwapChainVersion(swapChain);\n        }\n#else\n        /// <summary>\n        ///   Creates or reinitializes the Swap-Chain on the desktop Windows platform.\n        /// </summary>\n        /// <exception cref=\"InvalidOperationException\">\n        ///   <see cref=\"PresentationParameters.DeviceWindowHandle\"/> is <see langword=\"null\"/> or\n        ///   the <see cref=\"WindowHandle.Handle\"/> is invalid or zero.\n        /// </exception>\n        private void CreateSwapChainForWindows()\n        {\n            var hwndPtr = Description.DeviceWindowHandle.Handle;\n            if (hwndPtr == 0)\n                throw new InvalidOperationException($\"The {nameof(WindowHandle)}.{nameof(WindowHandle.Handle)} must not be zero.\");","sourceCodeStart":656,"sourceCodeEnd":692,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D/SwapChainGraphicsPresenter.Direct3D.cs#L656-L692","documentation":"On UWP, the swapchain creation code switches on DeviceWindowHandle.Context to choose the correct CreateSwapChainFor*CoreWindow/ForComposition API. If the Context value is not one of the recognized UWP window context types (CoreWindow, composition/IInspectable surface, etc.), no DXGI API matches, so CreateSwapChainForUWP throws NotSupportedException in its default case.","triggerScenarios":"Creating a SwapChainGraphicsPresenter on UWP with DeviceWindowHandle.Context set to a string other than 'CoreWindow' or the supported UWP context types — e.g. passing a plain Win32-style handle context into a UWP build.","commonSituations":"Sharing window-handle construction code between desktop Win32 and UWP builds; passing a null/empty or misspelled Context string; embedding Stride in a custom UWP shell whose window type is not CoreWindow.","solutions":["Set DeviceWindowHandle.Context to a supported UWP value ('CoreWindow' or the supported composition context) when running on UWP.","Ensure the window handle is created by the platform-appropriate helper (UWP window plumbing) rather than desktop Win32 code.","If embedding in a non-CoreWindow UWP surface, use the supported composition path (CreateSwapChainForComposition) recognized by the switch, or patch the switch to support it."],"exampleFix":"// before\nvar handle = new WindowHandle { Context = \"Hwnd\", Handle = nativePtr }; // desktop-style context on UWP\n// after\nvar handle = new WindowHandle { Context = \"CoreWindow\", Handle = coreWindowPtr };","handlingStrategy":"validation","validationCode":"if (OperatingSystem.IsWindows() && IsUwp())\n{\n    var ctx = description.DeviceWindowHandle?.Context;\n    if (ctx != \"CoreWindow\" && ctx != /* other supported context */ null)\n        throw new InvalidOperationException($\"Unsupported UWP window context: {ctx}\");\n}","typeGuard":"bool IsValidUwpContext(WindowHandle h) => h?.Context == \"CoreWindow\";","tryCatchPattern":"try { presenter = new SwapChainGraphicsPresenter(device, desc); }\ncatch (NotSupportedException ex) { logger.LogError(ex, \"Unsupported UWP window context\"); throw; }","preventionTips":["Create window handles with the platform-appropriate Stride helper","Never reuse desktop HWND context strings in UWP builds","Verify Context before presenter construction in cross-platform code"],"tags":["direct3d","uwp","swapchain","graphics","stride"],"backgroundTag":"unsupported-enum-value","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"}