{"record":{"id":"1fcf7af5da9bf03b","repo":"git-ecosystem/git-credential-manager","slug":"objectdisposedexception-gettype-name","errorCode":null,"errorMessage":"ObjectDisposedException(GetType().Name)","messagePattern":"ObjectDisposedException\\(GetType\\(\\)\\.Name\\)","errorType":"exception","errorClass":"ObjectDisposedException","httpStatus":null,"severity":"error","filePath":"src/Core/DisposableObject.cs","lineNumber":20,"sourceCode":"\nnamespace GitCredentialManager\n{\n    /// <summary>\n    /// An object that implements the <see cref=\"IDisposable\"/> interface and the disposable pattern.\n    /// </summary>\n    public abstract class DisposableObject : IDisposable\n    {\n        private bool _isDisposed;\n\n        /// <summary>\n        /// Throw an exception if the object has been disposed.\n        /// </summary>\n        /// <exception cref=\"ObjectDisposedException\">Thrown if the object has been disposed.</exception>\n        protected void ThrowIfDisposed()\n        {\n            if (_isDisposed)\n            {\n                throw new ObjectDisposedException(GetType().Name);\n            }\n        }\n\n        /// <summary>\n        /// Called when unmanaged resources should be released and memory freed.\n        /// </summary>\n        protected virtual void ReleaseUnmanagedResources() { }\n\n        /// <summary>\n        /// Called when managed resources should be released.\n        /// </summary>\n        protected virtual void ReleaseManagedResources() { }\n\n        /// <summary>\n        /// Called when the application is being terminated. Clean up and release any resources.\n        /// </summary>\n        /// <param name=\"disposing\">True if the instance is being disposed, false if being finalized.</param>\n        private void Dispose(bool disposing)","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/DisposableObject.cs#L2-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ninstance.Dispose();\ninstance.DoWork(); // throws\n// after\nif (!instance.IsDisposed) instance.DoWork();","handlingStrategy":"try-catch","validationCode":"if (obj.IsDisposed) return; // guard before use","typeGuard":"function isAlive<T extends { IsDisposed: boolean }>(o: T | null): o is T {\n  return o != null && !o.IsDisposed;\n}","tryCatchPattern":"try {\n  instance.DoWork();\n} catch (ObjectDisposedException) {\n  // recreate the instance and retry once, or abort the callback\n  instance = Recreate();\n}","preventionTips":["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"],"tags":["dotnet","objectdisposed","lifecycle","disposal"],"backgroundTag":"invalid-state-transition","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}