Repository navigation
Description
Current behavior 🐛
On the Skia renderer, SvgImageSource differs from WinUI in three ways (seen on master with both the Svg.Skia add-in and the managed SVG engine, and on 6.8):
- When the stream isn't SVG (for example a PNG),
await SetSourceAsync(stream)returnsSvgImageSourceLoadStatus.InvalidFormat. WinUI throwsArgumentException(E_INVALIDARG). Both raiseOpenFailedwithInvalidFormat. Openedis raised for every successful load of the same source: eachSetSourceAsync, each newUriSource. WinUI raises it only for the first successful load of a givenSvgImageSource.Image.ImageOpenedandImageBrush.ImageOpenedare raised for every load of an SVG source they show. WinUI raises them together with the source'sOpened, so only for its first successful load.
Expected behavior 🎯
Same as WinUI:
- A failed load still raises
OpenFailedwith the status, and the operation fails, so awaiting it throwsArgumentExceptionfor content that isn't SVG. WinUI completes the operation with the failure's HRESULT (SvgImageSourceSetSourceAsyncOperation::CoreSetError,CImageSource::OnImageViewUpdated). Openedis raised once per source.CSvgImageSource::OnDownloadImageAvailableImplfires it only whilem_frameIndexis 0, and for an SVG nothing resets that index (CBitmapImage::PrepareDecoderesets it only for bitmaps). WinUI's ownSvgImageSourceTestsuses a new instance when it expectsOpeneda second time.CImageSource::FireImageOpenednotifies the images and brushes showing the source at the same time as it raisesOpened, so theirImageOpenedfollows the same rule.
How to reproduce it (as minimally and precisely as possible) 🔬
var source = new SvgImageSource();
var opened = 0;
var imageOpened = 0;
source.Opened += (_, _) => opened++;
MyImage.ImageOpened += (_, _) => imageOpened++;
MyImage.Source = source;
await source.SetSourceAsync(svgStream1);
await source.SetSourceAsync(svgStream2);
// Uno: opened == 2, imageOpened == 2. WinUI: 1 and 1.
await source.SetSourceAsync(pngStream);
// Uno: returns InvalidFormat. WinUI: throws ArgumentException (0x80070057).Measured on WinAppSDK with runtime tests that make the same calls with file streams and ms-appdata URIs.
Workaround 🛠️
Handle both outcomes: check the returned status and catch ArgumentException. Use OpenFailed for the failure status, and don't rely on Opened/ImageOpened after the first load (or create a new SvgImageSource for each load).
Affected platforms 📱💻🖥️
WebAssembly, Android, iOS, Desktop (Windows), Desktop (macOS), Desktop (X11) (Skia renderer)
Uno.Sdk version (and other relevant versions) 📦
Master (7.0 dev) and 6.8.
IDE version 🧑💻
Not IDE related
Anything else we need to know? 💬
Found while fixing #25554 (stream SVG not drawn on 6.x).
One related difference remains. WinUI decodes a UriSource SVG only once an element shows it, while Uno opens it as soon as UriSource is set. So on WinUI an Image given a source that already opened from a stream doesn't get ImageOpened, but it does for a URI source. Uno can't tell those two cases apart without changing when URI sources load.
Activity