{"record":{"id":"93381f6872df9633","repo":"unoplatform/uno","slug":"mediaplayerpresenterextension-must-be-initialized","errorCode":null,"errorMessage":"MediaPlayerPresenterExtension must be initialized with a MediaPlayer instance","messagePattern":"MediaPlayerPresenterExtension must be initialized with a MediaPlayer instance","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/AddIns/Uno.UI.MediaPlayer.WebAssembly/MediaPlayerExtension.cs","lineNumber":52,"sourceCode":"\tprivate bool _isLoopingEnabled;\n\tprivate bool _isLoopingAllEnabled;\n\tprivate List<Uri>? _playlistItems;\n\tprivate int _playlistIndex;\n\tprivate TimeSpan _naturalDuration;\n\tprivate Uri? _uri;\n\tprivate bool _anonymousCors = FeatureConfiguration.AnonymousCorsDefault;\n\n\tconst string MsAppXScheme = \"ms-appx\";\n\n\tpublic MediaPlayerExtension(object owner)\n\t{\n\t\tif (owner is MediaPlayer player)\n\t\t{\n\t\t\t_owner = player;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tthrow new InvalidOperationException($\"MediaPlayerPresenterExtension must be initialized with a MediaPlayer instance\");\n\t\t}\n\n\t\tlock (_instances)\n\t\t{\n\t\t\t_instances[_owner] = this;\n\t\t}\n\t}\n\n\t~MediaPlayerExtension()\n\t{\n\t\tlock (_instances)\n\t\t{\n\t\t\t_instances.Remove(_owner);\n\t\t}\n\t}\n\n\tinternal static MediaPlayerExtension? GetByMediaPlayer(MediaPlayer mediaPlayer)\n\t{","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/AddIns/Uno.UI.MediaPlayer.WebAssembly/MediaPlayerExtension.cs#L34-L70","documentation":"InvalidOperationException thrown by the MediaPlayerExtension constructor (WebAssembly) when the 'owner' argument is not a MediaPlayer instance. The add-in is registered via ApiExtension to implement IMediaPlayerExtension and is constructed with the owning object; the framework contract requires that owner to be a MediaPlayer. A non-MediaPlayer owner indicates a misconfigured extensibility registration or manual misuse.","triggerScenarios":"Manually new-ing MediaPlayerExtension with a non-MediaPlayer object; a wrong ApiExtension registration wiring it to a different type; the framework passing the wrong owner due to an add-in version mismatch between Uno.UI and the WebAssembly media extension.","commonSituations":"Mixing incompatible Uno.UI and Uno.UI.MediaPlayer.WebAssembly package versions; a custom IMediaPlayerExtension registration that instantiates with the presenter instead of the player; reflection-based construction passing the wrong object.","solutions":["Ensure Uno.UI.MediaPlayer.WebAssembly package version matches the Uno.UI version in use.","Do not construct MediaPlayerExtension directly; let the framework's ApiExtension resolution create it with the MediaPlayer owner.","If wiring manually, pass the MediaPlayer instance, not the MediaPlayerPresenter/element.","Verify [assembly: ApiExtension(...)] registration targets the correct owner type."],"exampleFix":"// before — wrong owner type\nvar ext = new MediaPlayerExtension(mediaPlayerPresenter);\n\n// after — correct owner\nvar ext = new MediaPlayerExtension(mediaPlayer);","handlingStrategy":"type-guard","validationCode":"// Only construct with a MediaPlayer owner\nif (owner is MediaPlayer mp)\n    _ext = new MediaPlayerExtension(mp);\nelse\n    throw new ArgumentException(\"owner must be a MediaPlayer\", nameof(owner));","typeGuard":"bool IsMediaPlayerOwner(object owner) => owner is MediaPlayer;","tryCatchPattern":null,"preventionTips":["Let the framework's ApiExtension resolution construct MediaPlayerExtension; don't new it manually.","Keep Uno.UI and Uno.UI.MediaPlayer.WebAssembly versions in sync.","Pass the MediaPlayer, never the presenter/element, as owner."],"tags":["media-player","wasm","extensibility","constructor","uno-platform"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}