HandyOrg/HandyControl · error · NotSupportedException
Can't call EndInit without first calling BeginInit.
Error message
Can't call EndInit without first calling BeginInit.
What it means
JumpList.EndInit finalizes ISupportInitialize by applying the list to the application (ApplyFromApplication), but only when _initializing is true, i.e. a matching BeginInit ran. Calling EndInit without BeginInit throws NotSupportedException "Can't call EndInit without first calling BeginInit."
Solutions
- Always pair the calls: wrap population in try/finally so EndInit only runs after a successful BeginInit and is not called twice.
- Track a bool _initialized flag in your code and only call EndInit when true.
- If the list was populated without the BeginInit/EndInit pattern, call JumpList.ApplyFromApplication-equivalent flow correctly: BeginInit, mutate, EndInit once.
- Create a new JumpList instance if initialization state is uncertain, rather than re-calling EndInit.
Example fix
// before
if (items.Count == 0) return; // BeginInit skipped
jumpList.EndInit(); // throws: no BeginInit
// after
jumpList.BeginInit();
try { foreach (var i in items) jumpList.JumpItems.Add(i); }
finally { jumpList.EndInit(); } Defensive patterns
Strategy: validation
Validate before calling
if (!beginInitCalled) return; // EndInit requires a prior BeginInit
Try / catch
try { jumpList.EndInit(); }
catch (NotSupportedException ex) { Log.Error(ex.Message); /* BeginInit was never called */ } Prevention
- Always use try/finally around population so Begin/End pairs stay balanced.
- Track your own bool flag and only call EndInit when BeginInit succeeded.
- Call EndInit exactly once per BeginInit — never on retry paths after exceptions.
- Centralize jump-list initialization in one helper to prevent mismatched pairs.
When it happens
Trigger: Calling EndInit() on a JumpList that never had BeginInit() called; calling EndInit() twice; a code path where an exception occurred between BeginInit and EndInit and EndInit is retried.
Common situations: Conditional code that skips BeginInit but unconditionally calls EndInit; duplicate initialization helpers both invoking EndInit; exception in the population code causing mismatched init pairs on retry.
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
- Calls to BeginInit cannot be nested.
- NotSupportedException
- NotSupportedException
- NotSupportedException
- NotSupportedException
AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14).
Data as JSON: /api/errors/03e998313f0a3fe7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Shared/Microsoft.Windows.Shell/JumpList.cs:139
}
[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "BeginInit")]
public void BeginInit()
{
if (!this._IsUnmodified)
{
throw new InvalidOperationException("Calls to BeginInit cannot be nested.");
}
this._initializing = new bool?(true);
}
[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "EndInit")]
[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "BeginInit")]
public void EndInit()
{
if (this._initializing != true)
{
throw new NotSupportedException("Can't call EndInit without first calling BeginInit.");
}
this._initializing = new bool?(false);
this.ApplyFromApplication();
}
private static string _RuntimeId
{
get
{
string result;
HRESULT hrLeft = NativeMethods.GetCurrentProcessExplicitAppUserModelID(out result);
if (hrLeft == HRESULT.E_FAIL)
{
hrLeft = HRESULT.S_OK;
result = null;
}
hrLeft.ThrowIfFailed();
return result;View on GitHub (pinned to 2c0875ebd6)