{"record":{"id":"67b9cce9ecfb11c9","repo":"unoplatform/uno","slug":"owner-must-be-a-svgimagesource-instance","errorCode":null,"errorMessage":"Owner must be a SvgImageSource instance.","messagePattern":"Owner must be a SvgImageSource instance\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/AddIns/Uno.UI.Svg/SvgProvider.cs","lineNumber":47,"sourceCode":"public partial class SvgProvider : ISvgProvider\n{\n#if !__NETSTD_REFERENCE__\n\tprivate readonly SvgImageSource _owner;\n\tprivate readonly CompositeDisposable _disposables = new();\n\n\tprivate SKSvg? _skSvg;\n\tprivate SKBitmap? _skBitmap;\n#endif\n\n\tpublic SvgProvider(object owner)\n\t{\n#if __NETSTD_REFERENCE__\n\t\tthrow new PlatformNotSupportedException();\n#else\n\n\t\tif (owner is not SvgImageSource svgImageSource)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\"Owner must be a SvgImageSource instance.\");\n\t\t}\n\n\t\t_owner = svgImageSource;\n\n\t\t_disposables.Add(_owner.RegisterDisposablePropertyChangedCallback(SvgImageSource.RasterizePixelHeightProperty, SourcePropertyChanged));\n\t\t_disposables.Add(_owner.RegisterDisposablePropertyChangedCallback(SvgImageSource.RasterizePixelWidthProperty, SourcePropertyChanged));\n#endif // __NETSTD_REFERENCE__\n\t}\n\n\tpublic event EventHandler? SourceLoaded;\n\n#if !__NETSTD_REFERENCE__\n\tinternal event EventHandler? SourceUpdated;\n\n\tinternal SKSvg? SkSvg => _skSvg;\n\n\tinternal SKBitmap? SkBitmap => _skBitmap;\n#endif","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/AddIns/Uno.UI.Svg/SvgProvider.cs#L29-L65","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Let the framework construct SvgProvider via ApiExtensibility from a real SvgImageSource; do not instantiate it manually with arbitrary owners.","If constructing in code/tests, pass an actual SvgImageSource instance.","Check the [assembly: ApiExtension] attribute targets ISvgImageSource -> SvgProvider correctly."],"exampleFix":"// before\nvar provider = new SvgProvider(new BitmapImage());\n\n// after\nvar source = new SvgImageSource();\nvar provider = new SvgProvider(source); // or let the framework resolve it","handlingStrategy":"validation","validationCode":"if (owner is not SvgImageSource) throw new ArgumentException(nameof(owner));\nvar provider = new SvgProvider(owner);","typeGuard":"static bool IsValidOwner(object owner) => owner is SvgImageSource;","tryCatchPattern":null,"preventionTips":["Let the framework resolve SvgProvider from a real SvgImageSource via ApiExtensibility.","Do not pass generic image-source types to SvgProvider.","Verify [assembly: ApiExtension] maps ISvgImageSource to SvgProvider."],"tags":["svg","type-guard","extension","misuse"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}