dotnet/wpf · error · NotSupportedException
SR.JumpList_CantCallUnbalancedEndInit
Error message
SR.JumpList_CantCallUnbalancedEndInit
What it means
JumpList uses the ISupportInitialize two-phase pattern: EndInit commits (and optionally auto-applies) the list. EndInit throws NotSupportedException when there is no matching BeginInit in progress (_initializing != true), because committing an uninitialized list breaks the protocol.
Solutions
- Ensure every EndInit() is paired with exactly one prior BeginInit() on the same instance.
- Wrap BeginInit/EndInit in try/finally only when BeginInit succeeded; otherwise skip EndInit.
- Track initialization state yourself with a flag before calling EndInit.
- Use Apply() alone if you do not need two-phase initialization.
Example fix
// before
jumpList.EndInit(); // no BeginInit was called -> NotSupportedException
// after
jumpList.BeginInit();
jumpList.JumpItems.Add(new JumpTask { ... });
jumpList.EndInit(); Defensive patterns
Strategy: validation
Validate before calling
bool inInit = false;
void SafeEndInit(JumpList jl)
{
if (!inInit) throw new InvalidOperationException("EndInit without BeginInit");
jl.EndInit();
inInit = false;
} Try / catch
try { jumpList.EndInit(); }
catch (NotSupportedException ex) { Log.Warn("Unbalanced EndInit on JumpList", ex); } Prevention
- Always pair BeginInit/EndInit in the same scope.
- Do not call EndInit in a finally block unless BeginInit succeeded.
- Track initialization state with a boolean wrapper.
- Consider using Apply() instead of the ISupportInitialize pattern.
When it happens
Trigger: Calling EndInit() on a JumpList that never had BeginInit() called, or after EndInit()/Apply() already completed the cycle.
Common situations: Cleanup code that calls EndInit in a finally block even when BeginInit threw; copying init code from a class that does not require BeginInit; calling EndInit twice.
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.JumpList_CantNestBeginInitCalls
- By default, ToolTip property does not support ToolTip…
- Cannot convert from type.
- Cannot convert to type.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/958a606a2c73efea.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs:368
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);
}
_initializing = false;
// EndInit only implicitly applies the list if the current Application has been set as an attached property.
ApplyFromApplication();
}
#endregion
/// <summary>
/// Get the AppUserModelId for the running process.
/// </summary>
/// <remarks>
/// This is a Shell property that currently is only used as part of a heuristic
/// for what taskbar item an HWND should be associated with, e.g. you can put
/// windows from multiple processes into the same group, or you can prevent glomming
/// of HWNDs that would otherwise be shown together.View on GitHub (pinned to 81131a70a4)