{"record":{"id":"2ef9aee6dc52a12d","repo":"dotnet/wpf","slug":"stream-name-cannot-be-0","errorCode":null,"errorMessage":"Stream name cannot be '{0}'.","messagePattern":"Stream name cannot be '(.+?)'\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs","lineNumber":268,"sourceCode":"    // public Methods\n\n    /// <summary>\n    /// Creates \"this\" stream\n    /// </summary>\n    /// <param name=\"name\">Name of stream</param>\n    /// <param name=\"compressionOption\">CompressionOptiont</param>\n    /// <param name=\"encryptionOption\">EncryptionOption</param>\n    /// <returns>Reference to new stream</returns>\n    public StreamInfo CreateStream( string name, CompressionOption compressionOption, EncryptionOption encryptionOption )\n    {\n        CheckDisposedStatus();\n\n        //check the arguments\n        ArgumentNullException.ThrowIfNull(name);\n\n        // Stream names: we preserve casing, but do case-insensitive comparison (Native CompoundFile API behavior)\n        if (string.Equals(name, EncryptedPackageEnvelope.PackageStreamName, StringComparison.OrdinalIgnoreCase))\n            throw new ArgumentException(SR.Format(SR.StreamNameNotValid,name));\n\n        //create a new streaminfo object\n        StreamInfo streamInfo = new StreamInfo(this, name, compressionOption, encryptionOption);\n        if (streamInfo.InternalExists())\n        {\n            throw new IOException(SR.StreamAlreadyExist);\n        }\n\n        //Define the compression and encryption options in the dataspacemanager\n        DataSpaceManager manager = Root.GetDataSpaceManager();\n        string dataSpaceLabel = null;\n            \n        if (manager != null)\n        {\n            //case : Compression option is set. Stream need to be compressed. Define compression transform.\n            //At this time, we only treat CompressionOption - Normal and None. The rest are treated as Normal\n            if (compressionOption != CompressionOption.NotCompressed)\n            {","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs#L250-L286","documentation":"StorageInfo.CreateStream rejects the reserved stream name used by EncryptedPackageEnvelope (the encrypted-package marker in Rights-Managed/protected compound documents). Because the name collides with a special package stream, the library throws ArgumentException with the 'Stream name cannot be ...' message.","triggerScenarios":"Calling storage.CreateStream with a name equal (case-insensitively) to EncryptedPackageEnvelope.PackageStreamName, e.g. creating a user stream named like the encrypted-package marker.","commonSituations":"Applications writing custom parts into XPS/OPC compound files that accidentally pick the reserved encrypted-package name; code that derives stream names from user input without filtering reserved names.","solutions":["Choose a different stream name that does not match the reserved EncryptedPackageEnvelope.PackageStreamName","Compare the intended name against EncryptedPackageEnvelope.PackageStreamName (case-insensitive) before calling CreateStream","If writing an actual encrypted package, use EncryptedPackageEnvelope APIs instead of raw CreateStream"],"exampleFix":"// before\nstorage.CreateStream(userSuppliedName, CompressionOption.NotCompressed);\n// after\nif (string.Equals(userSuppliedName, EncryptedPackageEnvelope.PackageStreamName, StringComparison.OrdinalIgnoreCase))\n    userSuppliedName = \"Content\" + userSuppliedName;\nstorage.CreateStream(userSuppliedName, CompressionOption.NotCompressed);","handlingStrategy":"validation","validationCode":"bool reserved = string.Equals(name, EncryptedPackageEnvelope.PackageStreamName, StringComparison.OrdinalIgnoreCase);\nif (!reserved) storage.CreateStream(name, CompressionOption.NotCompressed);","typeGuard":"static bool IsReservedStreamName(string name) => string.Equals(name, EncryptedPackageEnvelope.PackageStreamName, StringComparison.OrdinalIgnoreCase);","tryCatchPattern":"try { storage.CreateStream(name, CompressionOption.NotCompressed); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"cannot be\")) { /* pick another name */ }","preventionTips":["Filter user-derived stream names against EncryptedPackageEnvelope.PackageStreamName","Never allow raw user input as compound-file stream names without validation"],"tags":["invalid-argument","reserved-name","compound-file","stream"],"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"}