{"record":{"id":"b78b29fbe5f17456","repo":"dotnet/wpf","slug":"sr-dataspacelabelinvalidempty","errorCode":null,"errorMessage":"SR.DataSpaceLabelInvalidEmpty","messagePattern":"SR\\.DataSpaceLabelInvalidEmpty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs","lineNumber":444,"sourceCode":"        /// <param name=\"dataSpace\">Data space encoding</param>\n        /// <returns>Stream object to manipulate data</returns>\n        internal Stream Create( FileMode mode, FileAccess access, string dataSpace )\n        {\n            CheckDisposedStatus();\n        \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            }","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs#L426-L462","documentation":"ArgumentException thrown by StreamInfo.Create when the dataSpace label argument is a non-null but zero-length string. The data space label names a transform/encryption data space to associate with the new stream; an empty string is not a meaningful label, so the library rejects it immediately. Pass null for 'no data space' or a valid non-empty label.","triggerScenarios":"Calling streamInfo.Create(content, access, \"\") or Create(..., dataSpace: string.Empty) — an empty-string label instead of null.","commonSituations":"Building the label from configuration or user input where an empty value wasn't normalized to null; string concatenation that yields \"\".","solutions":["Pass null instead of \"\" when no data space label is needed.","Normalize empty strings to null at the call site before invoking Create.","If a label is intended, supply the correct non-empty data space name (e.g. \"DRMTransform\")."],"exampleFix":"// before\nstreamInfo.Create(content, FileAccess.Write, label ?? \"\");\n// after\nstreamInfo.Create(content, FileAccess.Write,\n    string.IsNullOrEmpty(label) ? null : label);","handlingStrategy":"validation","validationCode":"if (dataSpace != null && dataSpace.Length == 0) throw new ArgumentException(\"dataSpace must be null or a non-empty label.\");","typeGuard":"bool IsValidDataSpaceLabel(string dataSpace) => dataSpace == null || dataSpace.Length > 0;","tryCatchPattern":"try { streamInfo.Create(content, access, dataSpace); }\ncatch (ArgumentException) { streamInfo.Create(content, access, null); }","preventionTips":["Normalize empty strings to null before passing optional label parameters.","Coalesce with string.IsNullOrEmpty at API boundaries.","Prefer nullable semantics for optional names."],"tags":["argument","validation","empty-string","packaging","dataspace"],"backgroundTag":"empty-required-field","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"}