{"record":{"id":"790310a7f126fa38","repo":"unoplatform/uno","slug":"generatebitmap-is-not-supported-by-this-platform","errorCode":null,"errorMessage":"GenerateBitmap is not supported by this platform","messagePattern":"GenerateBitmap is not supported by this platform","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Presentation/SampleChooserViewModel.cs","lineNumber":1301,"sourceCode":"\t\t\tvar folder = await GetStorageFolderFromNameOrCreate(ct, folderName);\n\n\t\t\tif (_log.IsEnabled(LogLevel.Debug))\n\t\t\t{\n\t\t\t\t_log.Debug($\"Output folder for tests: {folder.Path}\");\n\t\t\t}\n\t\t}\n\n\t\tprivate\n#if !__WASM__\n\t\t\tasync\n#endif\n\t\t\tTask GenerateBitmap(CancellationToken ct\n\t\t\t, Microsoft.UI.Xaml.Media.Imaging.RenderTargetBitmap targetBitmap\n\t\t\t, StorageFile file\n\t\t\t, FrameworkElement content)\n\t\t{\n#if __WASM__\n\t\t\tthrow new NotSupportedException($\"GenerateBitmap is not supported by this platform\");\n#else\n\t\t\tvar element = Owner.XamlRoot.Content;\n\n\t\t\ttry\n\t\t\t{\n\t\t\t\ttargetBitmap = new Microsoft.UI.Xaml.Media.Imaging.RenderTargetBitmap();\n\n\t\t\t\tawait targetBitmap.RenderAsync(element).AsTask(ct);\n\n\t\t\t\tvar pixels = await targetBitmap.GetPixelsAsync().AsTask(ct);\n\n\t\t\t\tusing (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite).AsTask(ct))\n\t\t\t\t{\n\t\t\t\t\tvar encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream).AsTask(ct);\n\n\t\t\t\t\tencoder.SetPixelData(\n\t\t\t\t\t\tBitmapPixelFormat.Bgra8,\n\t\t\t\t\t\tBitmapAlphaMode.Ignore,","sourceCodeStart":1283,"sourceCodeEnd":1319,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Presentation/SampleChooserViewModel.cs#L1283-L1319","documentation":"Thrown by SampleChooserViewModel.GenerateBitmap on the WebAssembly (__WASM__) build. RenderTargetBitmap rendering to a PNG file via BitmapEncoder is not available on WASM, so the method short-circuits with NotSupportedException. The method is compiled conditionally: on non-WASM it is async and performs the render; on WASM it throws immediately.","triggerScenarios":"Running the sample-chooser screenshot/bitmap-generation flow under the WASM host. The build define __WASM__ routes execution to the throw branch.","commonSituations":"Test/CI harness targeting WASM that invokes screenshot generation; running the full SamplesApp on WASM where bitmap dumping is part of the test runner.","solutions":["Skip the bitmap-generation step on WASM — guard the caller with '#if !__WASM__' or a runtime platform check before invoking GenerateBitmap.","Run the screenshot flow on a non-WASM host (Skia desktop) where RenderTargetBitmap is supported.","If WASM screenshots are required, use the WASM HTML-capture/screenshot tooling instead of RenderTargetBitmap."],"exampleFix":"// before\n#if __WASM__\nthrow new NotSupportedException($\"GenerateBitmap is not supported by this platform\");\n#else\n... render ...\n#endif\n// after - guard the caller so the method is never entered on WASM\n#if !__WASM__\nawait GenerateBitmap(ct, targetBitmap, file, content);\n#else\n_log.Information(\"Skipping bitmap generation on WASM.\");\n#endif","handlingStrategy":"validation","validationCode":"#if !__WASM__\nawait GenerateBitmap(ct, targetBitmap, file, content);\n#else\n_log.Information(\"Bitmap generation skipped on WASM.\");\n#endif","typeGuard":null,"tryCatchPattern":"try { await GenerateBitmap(ct, targetBitmap, file, content); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"GenerateBitmap is not supported\"))\n{ _log.Information(ex.Message); }","preventionTips":["Gate platform-unsupported features with compile-time or runtime platform checks at the call site.","Run bitmap/screenshot flows on Skia desktop, not WASM.","Document which features are unavailable per platform."],"tags":["wasm","rendertargetbitmap","platform","bitmap","notsupported","samples"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}