{"record":{"id":"856c5b8dfd8c6c8a","repo":"dotnet/wpf","slug":"sr-audiovideo-invaliddependencyobject","errorCode":null,"errorMessage":"SR.AudioVideo_InvalidDependencyObject","messagePattern":"SR\\.AudioVideo_InvalidDependencyObject","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/AVElementHelper.cs","lineNumber":99,"sourceCode":"\n        #endregion\n\n        #region Internal and Private Properties / Methods\n\n        /// <summary>\n        /// Returns the helper class given a dependency object\n        /// </summary>\n        internal static AVElementHelper GetHelper(DependencyObject d)\n        {\n            MediaElement mediaElement = d as MediaElement;\n\n            if (mediaElement != null)\n            {\n                return mediaElement.Helper;\n            }\n            else\n            {\n                throw new ArgumentException(SR.AudioVideo_InvalidDependencyObject);\n            }\n        }\n\n        /// <summary>\n        /// MediaPlayer associated with the element.\n        /// </summary>\n        internal MediaPlayer Player\n        {\n            get\n            {\n                return _mediaPlayer;\n            }\n        }\n\n        /// <summary>\n        /// Base Uri to use when resolving relative Uri's\n        /// </summary>\n        internal Uri BaseUri","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/AVElementHelper.cs#L81-L117","documentation":"AVElementHelper.GetHelper throws this ArgumentException when the passed DependencyObject is not a MediaElement (the lookup of the associated MediaElement helper fails). Only media-capable elements (MediaElement) can be used with AVElementHelper.","triggerScenarios":"Calling AVElementHelper.OnCreate/GetHelper-style APIs with a DependencyObject that is not a MediaElement (e.g. an Image, Button, or a custom element).","commonSituations":"Passing the wrong element to media helper APIs in code-behind; wiring AVElementHelper in a generic control container loop where the child may not be a MediaElement.","solutions":["Check that the element is a MediaElement before calling AVElementHelper APIs (e.g. `if (obj is MediaElement me) ...`).","Pass the MediaElement instance itself, not its parent or a container.","Use VisualTreeHelper searches that filter to MediaElement if the element is located via the tree."],"exampleFix":"// before\nvar helper = AVElementHelper.OnCreate(someElement);\n// after\nif (someElement is MediaElement media)\n    var helper = AVElementHelper.OnCreate(media);","handlingStrategy":"type-guard","validationCode":"if (!(depObj is MediaElement)) throw new ArgumentException(\"AVElementHelper requires a MediaElement\");","typeGuard":"bool IsMediaElement(DependencyObject o) => o is MediaElement;","tryCatchPattern":"try { var el = AVElementHelper.OnCreate(obj); } catch (ArgumentException) { /* obj is not a MediaElement */ }","preventionTips":["Pass the MediaElement instance, not containers or parents","Pattern-match with `is MediaElement` before media helper calls"],"tags":["wpf","mediaelement","argument","type-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}