dotnet/wpf · error · InvalidOperationException
SR.Media_UriNotSpecified
Error message
SR.Media_UriNotSpecified
What it means
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.
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
Example fix
// before
var timeline = new MediaTimeline();
var clock = timeline.CreateClock(); // InvalidOperationException
// after
var timeline = new MediaTimeline(new Uri("media\\\\video.wmv", UriKind.Relative));
var clock = timeline.CreateClock(); Defensive patterns
Strategy: validation
Validate before calling
if (timeline == null || timeline.Source == null) throw new ArgumentException("MediaTimeline.Source must be set before creating a clock", nameof(timeline)); Type guard
bool HasSource(MediaTimeline t) => t?.Source != null;
Try / catch
try { var clock = timeline.CreateClock(); } catch (InvalidOperationException ex) when (ex.Message.Contains("Uri")) { Log("MediaTimeline has no Source; cannot start playback"); } Prevention
- Always set Source in XAML or constructor
- Verify data bindings for Source resolved before starting Storyboards
- Validate Source before CreateClock in code
When it happens
Trigger: 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.
Common situations: XAML MediaTimeline declared without Source, data binding failing to supply the URI before the clock is allocated, or programmatically constructing MediaTimeline and forgetting Source.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- SR.Media_NotAllowedWhileTimingEngineInControl
- Storyboard_MediaElementRequired
- Animation_AnimationTimelineTypeMismatch
- Animation_CalculatedValueIsInvalidForProperty
- Animation_ChildMustBeKeyFrame
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e4cbe84bdb7381e7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaTimeline.cs:125
#region Timeline
/// <summary>
/// Called by the Clock to create a type-specific clock for this
/// timeline.
/// </summary>
/// <returns>
/// A clock for this timeline.
/// </returns>
/// <remarks>
/// If a derived class overrides this method, it should only create
/// and return an object of a class inheriting from Clock.
/// </remarks>
protected internal override Clock AllocateClock()
{
if (Source == null)
{
throw new InvalidOperationException(SR.Media_UriNotSpecified);
}
MediaClock mediaClock = new MediaClock(this);
return mediaClock;
}
/// <summary>
/// Called by the base Freezable class to make this object
/// frozen.
/// </summary>
protected override bool FreezeCore(bool isChecking)
{
bool canFreeze = base.FreezeCore(isChecking);
if (!canFreeze)
{
return false;
}View on GitHub (pinned to 81131a70a4)