unoplatform/uno · error · InvalidOperationException

Owner must be a SvgImageSource instance.

Error message

Owner must be a SvgImageSource instance.

What it means

SvgProvider is the platform extension backing SvgImageSource; its constructor requires owner to be an SvgImageSource and stores property-change callbacks against it. On the __NETSTD_REFERENCE__ build it instead throws PlatformNotSupportedException, so this InvalidOperationException only fires on real runtimes where a non-SvgImageSource owner was passed. Like [42] it signals a broken extension-to-host binding rather than a user-data problem.

Source

Thrown at src/AddIns/Uno.UI.Svg/SvgProvider.cs:47

public partial class SvgProvider : ISvgProvider
{
#if !__NETSTD_REFERENCE__
	private readonly SvgImageSource _owner;
	private readonly CompositeDisposable _disposables = new();

	private SKSvg? _skSvg;
	private SKBitmap? _skBitmap;
#endif

	public SvgProvider(object owner)
	{
#if __NETSTD_REFERENCE__
		throw new PlatformNotSupportedException();
#else

		if (owner is not SvgImageSource svgImageSource)
		{
			throw new InvalidOperationException("Owner must be a SvgImageSource instance.");
		}

		_owner = svgImageSource;

		_disposables.Add(_owner.RegisterDisposablePropertyChangedCallback(SvgImageSource.RasterizePixelHeightProperty, SourcePropertyChanged));
		_disposables.Add(_owner.RegisterDisposablePropertyChangedCallback(SvgImageSource.RasterizePixelWidthProperty, SourcePropertyChanged));
#endif // __NETSTD_REFERENCE__
	}

	public event EventHandler? SourceLoaded;

#if !__NETSTD_REFERENCE__
	internal event EventHandler? SourceUpdated;

	internal SKSvg? SkSvg => _skSvg;

	internal SKBitmap? SkBitmap => _skBitmap;
#endif

View on GitHub (pinned to 0418340488)

Solutions

  1. Let the framework construct SvgProvider via ApiExtensibility from a real SvgImageSource; do not instantiate it manually with arbitrary owners.
  2. If constructing in code/tests, pass an actual SvgImageSource instance.
  3. Check the [assembly: ApiExtension] attribute targets ISvgImageSource -> SvgProvider correctly.

Example fix

// before
var provider = new SvgProvider(new BitmapImage());

// after
var source = new SvgImageSource();
var provider = new SvgProvider(source); // or let the framework resolve it
Defensive patterns

Strategy: validation

Validate before calling

if (owner is not SvgImageSource) throw new ArgumentException(nameof(owner));
var provider = new SvgProvider(owner);

Type guard

static bool IsValidOwner(object owner) => owner is SvgImageSource;

Prevention

When it happens

Trigger: Constructing SvgProvider with an object that is not SvgImageSource — a faulty ApiExtension registration, a manual `new SvgProvider(...)` in tests with the wrong source type, or aSvgImageSource subclass whose `is` check fails.

Common situations: Writing unit tests that instantiate SvgProvider directly with a dummy object; mis-registering the SVG add-in against a different image-source type; assembly resolution picking the wrong ISvgImageSource extension.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/67b9cce9ecfb11c9. Report an issue: GitHub.