dotnet/wpf · error · InvalidOperationException
SR.JumpList_CantNestBeginInitCalls
Error message
SR.JumpList_CantNestBeginInitCalls
What it means
JumpList implements ISupportInitialize, and BeginInit marks the list as being initialized. If the JumpList has already been modified (items added or properties changed) before BeginInit is called again, the second call throws InvalidOperationException because nested begin/init cycles are not supported. This guards the two-phase initialization contract that EndInit relies on.
Solutions
- Remove the redundant BeginInit() call — one Begin/End pair per JumpList instance is enough.
- If items must be batched, add them all between a single BeginInit/EndInit pair instead of re-entering BeginInit.
- Create a fresh JumpList instance for each initialization cycle instead of reusing a mutated one.
- Call EndInit() (or Apply()) to complete any outstanding cycle before starting a new one.
Example fix
// before
jumpList.BeginInit();
jumpList.JumpItems.Add(new JumpTask { ... });
jumpList.BeginInit(); // throws
// after
jumpList.BeginInit();
jumpList.JumpItems.Add(new JumpTask { ... });
jumpList.EndInit(); Defensive patterns
Strategy: validation
Validate before calling
if (jumpList.JumpItems.Count > 0)
throw new InvalidOperationException("BeginInit requires an unmodified JumpList; use a new instance."); Type guard
bool CanBeginInit(JumpList jl) => jl != null && jl.JumpItems.Count == 0;
Prevention
- Call BeginInit exactly once per JumpList instance.
- Batch all JumpItems additions between one BeginInit/EndInit pair.
- Never reuse a JumpList after EndInit for a new init cycle — create a new one.
- Prefer the simple Apply() flow when two-phase init is not needed.
When it happens
Trigger: Calling BeginInit() twice on the same JumpList instance without a matching EndInit(); calling BeginInit() after the list was mutated (e.g. JumpItems.Add) from a previous incomplete init cycle (IsUnmodified is false).
Common situations: XAML authors nesting JumpList.BeginInit in a template instantiated more than once; code that calls BeginInit defensively each time items are appended; re-initializing a cached JumpList instance after it was already used.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- SR.JumpList_CantApplyUntilEndInit
- SR.EndInitWithoutBeginInitNotSupported
- SR.Format(SR.PropertyMustHaveValue, "DataType"…
- SR.Illegal_InheritanceBehaviorSettor
- SR.Image_EndInitWithoutBeginInit
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/54e494e1627f76a7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs:352
&& !ShowRecentCategory
&& !ShowFrequentCategory;
}
}
#region ISupportInitialize Members
/// <summary>
/// Prepare the JumpList for modification.
/// </summary>
/// <remarks>
/// This works in concert with the Application.JumpList attached property. The JumpList will automatically be applied
/// to the current application when attached and a corresponding call to EndInit is made.
/// Nested calls to BeginInit are not allowed.
/// </remarks>
public void BeginInit()
{
if (!IsUnmodified)
{
throw new InvalidOperationException(SR.JumpList_CantNestBeginInitCalls);
}
_initializing = true;
}
/// <summary>
/// Signal the end of initialization of this JumpList. If it is attached to the current Application, apply the contents of the jump list.
/// </summary>
/// <remarks>
/// Calls to EndInit must be paired with calls to BeginInit.
/// </remarks>
public void EndInit()
{
if (_initializing != true)
{
throw new NotSupportedException(SR.JumpList_CantCallUnbalancedEndInit);
}
View on GitHub (pinned to 81131a70a4)