dotnet/wpf · error · ArgumentException
SR.DataSpaceLabelUndefined
Error message
SR.DataSpaceLabelUndefined
What it means
ArgumentException thrown by StreamInfo.Create when the supplied dataSpace label is non-empty but is not defined in the compound file's DataSpaceManager (DataSpaceIsDefined returns false). The label must reference a data space previously defined/registered in the file's data space map (e.g. a transform such as the RM/encryption transform).
Solutions
- Verify the label with root.GetDataSpaceManager().DataSpaceIsDefined(label) before calling Create.
- Register/define the data space in the DataSpaceManager first, or obtain the correct label from the transform installation (e.g. the standard encrypted-transform label).
- Pass null if you don't actually need a data space on the stream.
- Check for typos/case differences against the defined data space names.
Example fix
// before
streamInfo.Create(content, FileAccess.Write, "EncryptedSpace"); // not defined
// after
var dsm = storageRoot.GetDataSpaceManager();
string label = "EncryptedSpace";
if (!dsm.DataSpaceIsDefined(label))
throw new InvalidOperationException("Data space must be defined before use.");
streamInfo.Create(content, FileAccess.Write, label); Defensive patterns
Strategy: validation
Validate before calling
var dsm = parentStorage.Root.GetDataSpaceManager();
if (dataSpace != null && !dsm.DataSpaceIsDefined(dataSpace)) throw new ArgumentException($"Data space '{dataSpace}' is not defined in this compound file."); Try / catch
try { streamInfo.Create(content, access, dataSpace); }
catch (ArgumentException) { /* define/register the data space or pass null and retry */ } Prevention
- Call DataSpaceIsDefined before Create when using any label.
- Keep the canonical data space labels (transform names) in shared constants.
- Register transforms before creating streams that reference them.
- Don't hardcode labels copied from other files.
When it happens
Trigger: Calling streamInfo.Create(content, access, "MyTransform") where "MyTransform" was never added to the root's DataSpaceManager; typos in the label; applying a label to a file that was never set up with that transform.
Common situations: Hand-rolling rights-management/encryption on package streams; copying code that references a transform defined in a different file; renaming transforms without updating stream creation code.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.DataSpaceLabelInvalidEmpty
- Cannot have leading path delimiter.
- CompoundFile path must be non-empty.
- FileMode value is not valid.
- SR.CompoundFilePathNullEmpty
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/cd62521b52688054.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs:449
int grfMode = 0;
IStream createdSafeIStream = null;
DataSpaceManager dataSpaceManager = null;
// Check to make sure root container is not read-only, and that
// we're not pointlessly trying to create a read-only stream.
CreateTimeReadOnlyCheck( access );
// Check to see if the data space label is valid
if( null != dataSpace )
{
if( 0 == dataSpace.Length )
throw new ArgumentException(
SR.DataSpaceLabelInvalidEmpty);
dataSpaceManager = parentStorage.Root.GetDataSpaceManager();
if( !dataSpaceManager.DataSpaceIsDefined( dataSpace ) )
throw new ArgumentException(
SR.DataSpaceLabelUndefined);
}
openFileAccess = access;
// becasue of the stream caching mechanism we must adjust FileAccess parameter.
// We want to open stream with the widest access posible, in case Package was open in ReadWrite
// we need to open stream in ReadWrite even if user explicitly asked us to do ReadOnly/WriteOnly.
// There is a possibility of a next request coming in as as ReadWrite request, and we would like to
// take advanatage of the cached stream by wrapping with appropriate access limitations.
if (parentStorage.Root.OpenAccess == FileAccess.ReadWrite)
{
access = FileAccess.ReadWrite;
}
// Generate the access flags from the access parameter
SafeNativeCompoundFileMethods.UpdateModeFlagFromFileAccess( access, ref grfMode );
// Only SHARE_EXCLUSIVE for now, FileShare issue TBDView on GitHub (pinned to 81131a70a4)