{"record":{"id":"3ce1afb399271497","repo":"unoplatform/uno","slug":"this-platform-does-not-support-skcanvaselement-fo","errorCode":null,"errorMessage":"This platform does not support SKCanvasElement. For more information: https://aka.platform.uno/skcanvaselement","messagePattern":"This platform does not support SKCanvasElement\\. For more information: https://aka\\.platform\\.uno/skcanvaselement","errorType":"exception","errorClass":"PlatformNotSupportedException","httpStatus":null,"severity":"error","filePath":"src/AddIns/Uno.WinUI.Graphics2DSK/SKCanvasElement.cs","lineNumber":42,"sourceCode":"\t{\n\t\tif (ApiExtensibility.CreateInstance<SKCanvasVisualBaseFactory>(this, out var factory))\n\t\t{\n\t\t\treturn _skCanvasVisual = factory.CreateInstance((o, size) => RenderOverride((SKCanvas)o, size), Compositor.GetSharedCompositor());\n\t\t}\n\t\telse\n\t\t{\n\t\t\tthrow new InvalidOperationException($\"Failed to create an instance of {nameof(SKCanvasVisualBase)}\");\n\t\t}\n\t}\n\n\tinternal override bool IsViewHit() => true;\n#endif\n\n\tprotected SKCanvasElement()\n\t{\n\t\tif (!IsSupportedOnCurrentPlatform())\n\t\t{\n\t\t\tthrow new PlatformNotSupportedException($\"This platform does not support {nameof(SKCanvasElement)}. For more information: https://aka.platform.uno/skcanvaselement\");\n\t\t}\n\t}\n\n#if CROSSRUNTIME\n\tpublic static bool IsSupportedOnCurrentPlatform() => ApiExtensibility.IsRegistered<SKCanvasVisualBaseFactory>();\n#else\n\tpublic static bool IsSupportedOnCurrentPlatform() => false;\n#endif\n\n\t/// <summary>\n\t/// Invalidates the element and triggers a redraw.\n\t/// </summary>\n#if CROSSRUNTIME\n\tpublic void Invalidate() => _skCanvasVisual?.Invalidate();\n#else\n#pragma warning disable CS0109 // Member does not hide an inherited member; new keyword is not required\n\tpublic new void Invalidate() { }\n#pragma warning restore CS0109 // Member does not hide an inherited member; new keyword is not required","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/AddIns/Uno.WinUI.Graphics2DSK/SKCanvasElement.cs#L24-L60","documentation":"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].","triggerScenarios":"Constructing SKCanvasElement on a target where the Graphics2DSK add-in was compiled without CROSSRUNTIME defined, or where no SKCanvasVisualBaseFactory is registered for the runtime.","commonSituations":"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.","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."],"exampleFix":"// before\nvar el = new SKCanvasElement();\n\n// after\nif (!SKCanvasElement.IsSupportedOnCurrentPlatform())\n{\n\tthrow new PlatformNotSupportedException(\"SKCanvasElement not available on this head; use a Skia target.\");\n}\nvar el = new SKCanvasElement();","handlingStrategy":"validation","validationCode":"if (!SKCanvasElement.IsSupportedOnCurrentPlatform())\n{\n\tthrow new PlatformNotSupportedException(\"SKCanvasElement unavailable on this head.\");\n}\nvar el = new SKCanvasElement();","typeGuard":"static bool CanUseSKCanvasElement() => SKCanvasElement.IsSupportedOnCurrentPlatform();","tryCatchPattern":null,"preventionTips":["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."],"tags":["skia","graphics","skcanvaselement","platform","platformnotsupported"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}