{"record":{"id":"e4cbe84bdb7381e7","repo":"dotnet/wpf","slug":"sr-media-urinotspecified","errorCode":null,"errorMessage":"SR.Media_UriNotSpecified","messagePattern":"SR\\.Media_UriNotSpecified","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaTimeline.cs","lineNumber":125,"sourceCode":"\n        #region Timeline\n\n        /// <summary>\n        /// Called by the Clock to create a type-specific clock for this\n        /// timeline.\n        /// </summary>\n        /// <returns>\n        /// A clock for this timeline.\n        /// </returns>\n        /// <remarks>\n        /// If a derived class overrides this method, it should only create\n        /// and return an object of a class inheriting from Clock.\n        /// </remarks>\n        protected internal override Clock AllocateClock()\n        {\n            if (Source == null)\n            {\n                throw new InvalidOperationException(SR.Media_UriNotSpecified);\n            }\n\n            MediaClock mediaClock = new MediaClock(this);\n\n            return mediaClock;\n        }\n\n        /// <summary>\n        /// Called by the base Freezable class to make this object\n        /// frozen.\n        /// </summary>\n        protected override bool FreezeCore(bool isChecking)\n        {\n            bool canFreeze = base.FreezeCore(isChecking);\n            if (!canFreeze)\n            {\n                return false;\n            }","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaTimeline.cs#L107-L143","documentation":"MediaTimeline.AllocateClock throws InvalidOperationException when the timeline's Source (a URI) is null. A MediaClock cannot be allocated without a media source, so the timing engine refuses to create the clock.","triggerScenarios":"Starting an animation/clock from a MediaTimeline whose Source property was never set - e.g. calling CreateClock(), adding the timeline to a Storyboard and playing it, or binding the timeline in XAML without a Source attribute.","commonSituations":"XAML MediaTimeline declared without Source, data binding failing to supply the URI before the clock is allocated, or programmatically constructing MediaTimeline and forgetting Source.","solutions":["Set MediaTimeline.Source to a valid media URI before creating/starting clocks","Validate Source != null before calling CreateClock or starting the containing Storyboard","Ensure the Source binding resolves (check DataContext/binding errors) prior to playback"],"exampleFix":"// before\nvar timeline = new MediaTimeline();\nvar clock = timeline.CreateClock(); // InvalidOperationException\n// after\nvar timeline = new MediaTimeline(new Uri(\"media\\\\\\\\video.wmv\", UriKind.Relative));\nvar clock = timeline.CreateClock();","handlingStrategy":"validation","validationCode":"if (timeline == null || timeline.Source == null) throw new ArgumentException(\"MediaTimeline.Source must be set before creating a clock\", nameof(timeline));","typeGuard":"bool HasSource(MediaTimeline t) => t?.Source != null;","tryCatchPattern":"try { var clock = timeline.CreateClock(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Uri\")) { Log(\"MediaTimeline has no Source; cannot start playback\"); }","preventionTips":["Always set Source in XAML or constructor","Verify data bindings for Source resolved before starting Storyboards","Validate Source before CreateClock in code"],"tags":["wpf","media","animation","missing-value"],"backgroundTag":"missing-required-argument","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"}