stride3d/stride · error · NotSupportedException
Window context [ ] not supported while creating SwapChain
Error message
Window context [{Description.DeviceWindowHandle.Context}] not supported while creating SwapChain What it means
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.
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.
Example fix
// before
var handle = new WindowHandle { Context = "Hwnd", Handle = nativePtr }; // desktop-style context on UWP
// after
var handle = new WindowHandle { Context = "CoreWindow", Handle = coreWindowPtr }; Defensive patterns
Strategy: validation
Validate before calling
if (OperatingSystem.IsWindows() && IsUwp())
{
var ctx = description.DeviceWindowHandle?.Context;
if (ctx != "CoreWindow" && ctx != /* other supported context */ null)
throw new InvalidOperationException($"Unsupported UWP window context: {ctx}");
} Type guard
bool IsValidUwpContext(WindowHandle h) => h?.Context == "CoreWindow";
Try / catch
try { presenter = new SwapChainGraphicsPresenter(device, desc); }
catch (NotSupportedException ex) { logger.LogError(ex, "Unsupported UWP window context"); throw; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- SurfaceRotation ' ' is not supported on Direct3D presenters.
- The . must not be zero.
- Custom strides is not supported with packed PixelFormats
- Unexpected error on Present
- DeviceWindowHandle cannot be null
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/a0400baf9330544f.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Direct3D/SwapChainGraphicsPresenter.Direct3D.cs:674
if (result.IsFailure)
result.Throw();
// Finally, create the Swap-Chain
var coreWindow = ToComPtr((IUnknown*) Marshal.GetIUnknownForObject(Description.DeviceWindowHandle.NativeWindow));
result = dxgiFactory2.CreateSwapChainForCoreWindow(deviceAsIUnknown, coreWindow, in description, noOutput, ref swapChain);
if (result.IsFailure)
result.Throw();
SafeRelease(ref coreWindow);
SafeRelease(ref dxgiFactory2);
SafeRelease(ref dxgiAdapter);
SafeRelease(ref dxgiDevice2);
break;
}
default:
throw new NotSupportedException($"Window context [{Description.DeviceWindowHandle.Context}] not supported while creating SwapChain");
}
this.swapChain = swapChain;
swapChainVersion = GetLatestDxgiSwapChainVersion(swapChain);
}
#else
/// <summary>
/// Creates or reinitializes the Swap-Chain on the desktop Windows platform.
/// </summary>
/// <exception cref="InvalidOperationException">
/// <see cref="PresentationParameters.DeviceWindowHandle"/> is <see langword="null"/> or
/// the <see cref="WindowHandle.Handle"/> is invalid or zero.
/// </exception>
private void CreateSwapChainForWindows()
{
var hwndPtr = Description.DeviceWindowHandle.Handle;
if (hwndPtr == 0)
throw new InvalidOperationException($"The {nameof(WindowHandle)}.{nameof(WindowHandle.Handle)} must not be zero.");View on GitHub (pinned to 96fad776d2)