git-ecosystem/git-credential-manager · error · ObjectDisposedException
ObjectDisposedException(GetType().Name)
Error message
ObjectDisposedException(GetType().Name)
What it means
DisposableObject.ThrowIfDisposed throws ObjectDisposedException named after the concrete type when any member is used after the object's Dispose has run. It is a standard .NET lifecycle guard protecting GCM classes derived from DisposableObject from use-after-dispose bugs.
Solutions
- Audit object lifetime: ensure all work completes before Dispose is called.
- Cancel or unregister callbacks/timers/events before disposing the owner.
- Check _isDisposed (or a public IsDisposed) before invoking members on a possibly-disposed instance.
- Do not cache and reuse disposed instances; create a new instance instead.
Example fix
// before instance.Dispose(); instance.DoWork(); // throws // after if (!instance.IsDisposed) instance.DoWork();
Defensive patterns
Strategy: try-catch
Validate before calling
if (obj.IsDisposed) return; // guard before use
Type guard
function isAlive<T extends { IsDisposed: boolean }>(o: T | null): o is T {
return o != null && !o.IsDisposed;
} Try / catch
try {
instance.DoWork();
} catch (ObjectDisposedException) {
// recreate the instance and retry once, or abort the callback
instance = Recreate();
} Prevention
- Unsubscribe events/cancel tasks before disposing owners
- Treat Dispose as terminal; never call methods afterwards
- Use using/await using scopes so lifetime is lexical
- Check IsDisposed in long-lived callbacks and timers
When it happens
Trigger: Calling a method/property on a GCM object (e.g. an app/trace/context object derived from DisposableObject) after calling Dispose(), or after the owning framework disposed it; async callbacks completing after disposal.
Common situations: Background tasks or event handlers outliving the disposed host; disposing an object while another thread still holds a reference; calling methods in a finally block after explicit disposal.
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
AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11).
Data as JSON: /api/errors/1fcf7af5da9bf03b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Core/DisposableObject.cs:20
namespace GitCredentialManager
{
/// <summary>
/// An object that implements the <see cref="IDisposable"/> interface and the disposable pattern.
/// </summary>
public abstract class DisposableObject : IDisposable
{
private bool _isDisposed;
/// <summary>
/// Throw an exception if the object has been disposed.
/// </summary>
/// <exception cref="ObjectDisposedException">Thrown if the object has been disposed.</exception>
protected void ThrowIfDisposed()
{
if (_isDisposed)
{
throw new ObjectDisposedException(GetType().Name);
}
}
/// <summary>
/// Called when unmanaged resources should be released and memory freed.
/// </summary>
protected virtual void ReleaseUnmanagedResources() { }
/// <summary>
/// Called when managed resources should be released.
/// </summary>
protected virtual void ReleaseManagedResources() { }
/// <summary>
/// Called when the application is being terminated. Clean up and release any resources.
/// </summary>
/// <param name="disposing">True if the instance is being disposed, false if being finalized.</param>
private void Dispose(bool disposing)View on GitHub (pinned to e8ce762cd0)