unoplatform/uno · error · PlatformNotSupportedException
This platform does not support SKCanvasElement. For more inf
Error message
This platform does not support SKCanvasElement. For more information: https://aka.platform.uno/skcanvaselement
What it means
SKCanvasElement's protected constructor throws PlatformNotSupportedException when IsSupportedOnCurrentPlatform() is false. On non-CROSSRUNTIME builds IsSupportedOnCurrentPlatform() is a hardcoded `false`; on CROSSRUNTIME builds it returns ApiExtensibility.IsRegistered<SKCanvasVisualBaseFactory>(). So the throw means either the type is being constructed on a TFM that compiles it without CROSSRUNTIME, or no SKCanvasVisualBaseFactory is registered. This fires earlier and more cheaply than [47].
Source
Thrown at src/AddIns/Uno.WinUI.Graphics2DSK/SKCanvasElement.cs:42
{
if (ApiExtensibility.CreateInstance<SKCanvasVisualBaseFactory>(this, out var factory))
{
return _skCanvasVisual = factory.CreateInstance((o, size) => RenderOverride((SKCanvas)o, size), Compositor.GetSharedCompositor());
}
else
{
throw new InvalidOperationException($"Failed to create an instance of {nameof(SKCanvasVisualBase)}");
}
}
internal override bool IsViewHit() => true;
#endif
protected SKCanvasElement()
{
if (!IsSupportedOnCurrentPlatform())
{
throw new PlatformNotSupportedException($"This platform does not support {nameof(SKCanvasElement)}. For more information: https://aka.platform.uno/skcanvaselement");
}
}
#if CROSSRUNTIME
public static bool IsSupportedOnCurrentPlatform() => ApiExtensibility.IsRegistered<SKCanvasVisualBaseFactory>();
#else
public static bool IsSupportedOnCurrentPlatform() => false;
#endif
/// <summary>
/// Invalidates the element and triggers a redraw.
/// </summary>
#if CROSSRUNTIME
public void Invalidate() => _skCanvasVisual?.Invalidate();
#else
#pragma warning disable CS0109 // Member does not hide an inherited member; new keyword is not required
public new void Invalidate() { }
#pragma warning restore CS0109 // Member does not hide an inherited member; new keyword is not requiredView on GitHub (pinned to 0418340488)
Solutions
- Call SKCanvasElement.IsSupportedOnCurrentPlatform() before constructing the element and avoid instantiation when it returns false.
- Target a Skia-supported head (Skia Desktop / Skia-mobile) and ensure the SKCanvasVisualBaseFactory-registering host package is referenced.
- If the type was compiled without CROSSRUNTIME, switch to the CROSSRUNTIME configuration or use a different drawing surface.
Example fix
// before
var el = new SKCanvasElement();
// after
if (!SKCanvasElement.IsSupportedOnCurrentPlatform())
{
throw new PlatformNotSupportedException("SKCanvasElement not available on this head; use a Skia target.");
}
var el = new SKCanvasElement(); Defensive patterns
Strategy: validation
Validate before calling
if (!SKCanvasElement.IsSupportedOnCurrentPlatform())
{
throw new PlatformNotSupportedException("SKCanvasElement unavailable on this head.");
}
var el = new SKCanvasElement(); Type guard
static bool CanUseSKCanvasElement() => SKCanvasElement.IsSupportedOnCurrentPlatform();
Prevention
- Always call IsSupportedOnCurrentPlatform() before constructing SKCanvasElement.
- Use Skia targets for Skia 2D canvas work.
- Ensure the Graphics2DSK add-in is compiled with CROSSRUNTIME on the target head.
When it happens
Trigger: Constructing SKCanvasElement on a target where the Graphics2DSK add-in was compiled without CROSSRUNTIME defined, or where no SKCanvasVisualBaseFactory is registered for the runtime.
Common situations: Using SKCanvasElement in a head that does not support Skia 2D canvases (e.g. WASM-DOM, native iOS/Android without Skia); referencing the add-in but omitting the Skia host package that registers the factory.
Related errors
- Failed to create an instance of SKCanvasVisualBase
- Vertex shader failed to compile: {infoLog}
- Fragment shader failed to compile: {infoLog}
- PInvoke.RegisterClassEx failed: {Win32Helper.GetErrorMessage
- PInvoke.CreateWindowEx failed: {Win32Helper.GetErrorMessage(
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/3ce1afb399271497.
Report an issue: GitHub.