dotnet/wpf · error · ObjectDisposedException
SR.DataSpaceManagerDisposed
Error message
SR.DataSpaceManagerDisposed
What it means
DataSpaceManager throws ObjectDisposedException with message SR.DataSpaceManagerDisposed from its CheckDisposedStatus helper when any public/internal member is used after Dispose. This guards the compound-file data-space manager's internal dictionaries which are nulled on dispose.
Solutions
- Ensure the DataSpaceManager is created/reopened before use; do not use it after the owning CompoundFile is disposed.
- Track disposal with a boolean/CanRead-style check if you cache the manager across operations.
- Restructure code so all data-space work happens inside the compound file's open scope.
Example fix
// before
file.Close();
manager.DefineDataSpace(stack, label); // throws
// after
using (var file = CompoundFile.Open(path)) {
file.DataSpaceManager.DefineDataSpace(stack, label);
} Defensive patterns
Strategy: try-catch
Try / catch
try { manager.DefineDataSpace(stack, label); } catch (ObjectDisposedException) { manager = ReopenCompoundFile(path).DataSpaceManager; } Prevention
- Scope all DataSpaceManager usage inside the CompoundFile's open lifetime
- Avoid storing the manager in long-lived fields
When it happens
Trigger: Calling DataSpaceManager methods (e.g. DefineDataSpace, GetDataSpace) after DataSpaceManager.Dispose(); Debug.Asserts confirm disposed state (null maps) before the throw.
Common situations: Using a CompoundFile DataSpaceManager after the parent compound file was closed or its using-block ended.
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.StreamObjectDisposed
- SR.TransformStackValid
- The given data space label name is already in use.
- ' ' cannot contain the path delimiter: ' '.
- ' ' cannot start with the reserved character range…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/406c5948b3f0f0d1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/DataSpaceManager.cs:561
}
}
// Check to see if the dispose method has been called. If so, throw an
// ObjectDisposedException.
internal void CheckDisposedStatus()
{
// First check root
_associatedStorage.CheckRootDisposedStatus();
// Check if we've been disposed
if( null == _dataSpaceMap )
{
Debug.Assert( null == _dataSpaceDefinitions,
"Having a null data space map and a non-null data space definitions map is an inconsistent state" );
Debug.Assert( null == _transformDefinitions,
"Having a null data space map and a non-null transform definition map is an inconsistent state" );
throw new ObjectDisposedException(null, SR.DataSpaceManagerDisposed);
}
}
/// <summary>
/// Define a data space with the given stack of transform objects and
/// labeled with the given name. The transform stack is interpreted in
/// bottom-up order. (Clear-text transform is last.)
/// </summary>
/// <param name="transformStack">Transform stack</param>
/// <param name="newDataSpaceLabel">New data space label</param>
internal void DefineDataSpace( string[] transformStack, string newDataSpaceLabel )
{
CheckDisposedStatus();
// Data space must have at least one transform
if( null == transformStack ||
0 == transformStack.Length )
throw new ArgumentException(
SR.TransformStackValid);View on GitHub (pinned to 81131a70a4)