{"record":{"id":"16237e6fb24141c9","repo":"dotnet/wpf","slug":"sr-storagebasedpackagepropertiesdiposed","errorCode":null,"errorMessage":"SR.StorageBasedPackagePropertiesDiposed","messagePattern":"SR\\.StorageBasedPackagePropertiesDiposed","errorType":"exception","errorClass":"ObjectDisposedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/StorageBasedPackageProperties.cs","lineNumber":862,"sourceCode":"                            SR.Format(SR.UnknownDocumentProperty, fmtid.ToString(), propId),\n                            nameof(propId)\n                            );\n                }\n            }\n            else\n            {\n                throw new ArgumentException(\n                    SR.Format(SR.UnknownDocumentProperty, fmtid.ToString(), propId),\n                    nameof(fmtid)\n                    );\n            }\n        }\n\n        private void\n        CheckDisposed()\n        {\n            if (_disposed)\n                throw new ObjectDisposedException(null, SR.StorageBasedPackagePropertiesDiposed);\n        }\n\n        #endregion Private Methods\n\n        //------------------------------------------------------\n        //\n        //  Private Fields\n        //\n        //------------------------------------------------------\n\n        #region Private Fields\n\n        private bool _disposed;\n\n        private int _grfMode;  // Mode in which the compound file was opened.\n\n        //\n        // Interface to the OLE property sets in the compound file representing","sourceCodeStart":844,"sourceCodeEnd":880,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/StorageBasedPackageProperties.cs#L844-L880","documentation":"CheckDisposed throws ObjectDisposedException when any OLE property read/write is attempted on a StorageBasedPackageProperties that has already been disposed (its package or underlying storage was closed). The library tracks disposal and refuses further property access.","triggerScenarios":"Accessing package.PackageProperties properties (Title, Creator, etc.) after the containing Package was closed/disposed, or after the StorageBasedPackageProperties itself was disposed; holding the PackageProperties object past the package lifetime.","commonSituations":"Disposing the Package in a using block and then touching cached PackageProperties afterwards; closing the package on one thread/UI event while another code path still reads properties; long-lived caches of PackageProperties objects.","solutions":["Read or write all PackageProperties values before disposing/closing the Package; copy needed values into your own objects.","Keep the Package open (dispose it only when properties are no longer needed).","Check ObjectDisposedException in catch blocks when accessing properties on possibly-closed packages and treat the value as unavailable.","Restructure so PackageProperties access happens inside the same using scope as the Package."],"exampleFix":"// before: properties read after disposal\nusing (var pkg = Package.Open(path))\n{\n    props = pkg.PackageProperties;\n}\nConsole.WriteLine(props.Title); // ObjectDisposedException\n// after\nusing (var pkg = Package.Open(path))\n{\n    var title = pkg.PackageProperties.Title;\n}\nConsole.WriteLine(title);","handlingStrategy":"try-catch","validationCode":"bool CanAccess(Package pkg) => pkg != null && !disposedFlags.Contains(pkg); // track your own disposal state\nvar title = IsPackageOpen(pkg) ? pkg.PackageProperties.Title : null;","typeGuard":null,"tryCatchPattern":"try { title = pkg.PackageProperties.Title; }\ncatch (ObjectDisposedException) { title = null; /* package already closed */ }","preventionTips":["Read PackageProperties inside the same using scope as the Package","Copy property values out before closing the package","Never cache PackageProperties across package lifetime boundaries"],"tags":["wpf","packaging","object-disposed","lifetime"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}