{"record":{"id":"cd62521b52688054","repo":"dotnet/wpf","slug":"sr-dataspacelabelundefined","errorCode":null,"errorMessage":"SR.DataSpaceLabelUndefined","messagePattern":"SR\\.DataSpaceLabelUndefined","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs","lineNumber":449,"sourceCode":"        \n            int grfMode = 0;\n            IStream createdSafeIStream = null;\n            DataSpaceManager dataSpaceManager = null;\n\n            // Check to make sure root container is not read-only, and that\n            //  we're not pointlessly trying to create a read-only stream.\n            CreateTimeReadOnlyCheck( access );\n\n            // Check to see if the data space label is valid\n            if( null != dataSpace )\n            {\n                if( 0 == dataSpace.Length )\n                    throw new ArgumentException(\n                        SR.DataSpaceLabelInvalidEmpty);\n            \n                dataSpaceManager = parentStorage.Root.GetDataSpaceManager();\n                if( !dataSpaceManager.DataSpaceIsDefined( dataSpace ) )\n                    throw new ArgumentException(\n                        SR.DataSpaceLabelUndefined);\n            }\n\n            openFileAccess = access;\n            // becasue of the stream caching mechanism we must adjust FileAccess parameter. \n            // We want to open stream with the widest access posible, in case Package was open in ReadWrite \n            // we need to open stream in ReadWrite even if user explicitly asked us to do ReadOnly/WriteOnly. \n            // There is a possibility of a next request coming in as as ReadWrite request, and we would like to\n            // take advanatage of the cached stream by wrapping with appropriate access limitations.\n            if (parentStorage.Root.OpenAccess == FileAccess.ReadWrite)\n            {\n                access = FileAccess.ReadWrite;\n            }\n\n            // Generate the access flags from the access parameter\n            SafeNativeCompoundFileMethods.UpdateModeFlagFromFileAccess( access, ref grfMode );\n            \n            // Only SHARE_EXCLUSIVE for now, FileShare issue TBD","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs#L431-L467","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nstreamInfo.Create(content, FileAccess.Write, \"EncryptedSpace\"); // not defined\n// after\nvar dsm = storageRoot.GetDataSpaceManager();\nstring label = \"EncryptedSpace\";\nif (!dsm.DataSpaceIsDefined(label))\n    throw new InvalidOperationException(\"Data space must be defined before use.\");\nstreamInfo.Create(content, FileAccess.Write, label);","handlingStrategy":"validation","validationCode":"var dsm = parentStorage.Root.GetDataSpaceManager();\nif (dataSpace != null && !dsm.DataSpaceIsDefined(dataSpace)) throw new ArgumentException($\"Data space '{dataSpace}' is not defined in this compound file.\");","typeGuard":null,"tryCatchPattern":"try { streamInfo.Create(content, access, dataSpace); }\ncatch (ArgumentException) { /* define/register the data space or pass null and retry */ }","preventionTips":["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."],"tags":["argument","validation","dataspace","packaging","undefined-reference"],"backgroundTag":"invalid-argument-value","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"}