{"record":{"id":"cf57b88f2a1a8f04","repo":"dotnet/wpf","slug":"transform-label-name-is-already-in-use","errorCode":null,"errorMessage":"Transform label name is already in use.","messagePattern":"Transform label name is already in use\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/DataSpaceManager.cs","lineNumber":913,"sourceCode":"    /// </summary>\n    /// <param name=\"transformClassName\">Transform identification string</param>\n    /// <param name=\"newTransformLabel\">Label to use for new transform</param>\n    internal void DefineTransform(string transformClassName, string newTransformLabel )\n    {\n        CheckDisposedStatus();\n\n        // Check to see if transform name is obviously invalid\n        CU.CheckStringAgainstNullAndEmpty( transformClassName, \"Transform identifier name\" );\n\n        // Check to see if transform name is valid\n        CU.CheckStringAgainstNullAndEmpty( newTransformLabel, \"Transform label\" );\n\n        // Given transform name must not be a reserved string\n        CU.CheckStringAgainstReservedName( newTransformLabel, \"Transform label\" );\n\n        // Can't re-use an existing transform name\n        if( TransformLabelIsDefined( newTransformLabel ) )\n            throw new ArgumentException(\n                SR.TransformLabelInUse);\n\n        // Create class the transform object will use to communicate to us\n        TransformEnvironment transformEnvironment = new TransformEnvironment( this, newTransformLabel );\n\n        // Create a TransformInstance object to represent this transform instance.\n        TransformInstance newTransform = new TransformInstance(\n            TransformIdentifierTypes_PredefinedTransformName,\n            transformClassName,\n            null,\n            transformEnvironment );\n\n        SetTransformDefinition( newTransformLabel, newTransform );\n\n        // Create the transform object\n        IDataTransform transformObject = InstantiateDataTransformObject(\n                                                    TransformIdentifierTypes_PredefinedTransformName,\n                                                    transformClassName,","sourceCodeStart":895,"sourceCodeEnd":931,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/DataSpaceManager.cs#L895-L931","documentation":"DefineTransform refuses to register a new transform label that is already defined in this DataSpaceManager. After checking the label is not null/empty/reserved, it calls TransformLabelIsDefined and throws ArgumentException with SR.TransformLabelInUse if the name is taken. Transform labels are unique per manager instance.","triggerScenarios":"Calling DefineTransform with a label that was previously registered via an earlier DefineTransform call on the same DataSpaceManager, or a label that also maps to a built-in/predefined transform name already present after loading a file.","commonSituations":"Re-running initialization code twice against the same open package (e.g. re-opening a Package and re-defining transforms); name collisions when generating transform labels programmatically; opening a file whose data space info already defines the transform, then attempting to define it again.","solutions":["Check TransformLabelIsDefined(label) before calling DefineTransform and skip registration if it returns true.","Guard initialization so DefineTransform runs only once per DataSpaceManager lifetime.","Generate unique labels (append a counter or GUID) when creating transform names programmatically.","Catch ArgumentException with SR.TransformLabelInUse and reuse the existing transform instead of redefining it."],"exampleFix":"// before\nmanager.DefineTransform(\"CompressionTransform\", factory); // second call throws\n// after\nif (!manager.TransformLabelIsDefined(\"CompressionTransform\"))\n    manager.DefineTransform(\"CompressionTransform\", factory);","handlingStrategy":"validation","validationCode":"if (!manager.TransformLabelIsDefined(label))\n    manager.DefineTransform(label, factory);","typeGuard":null,"tryCatchPattern":"try { manager.DefineTransform(label, factory); }\ncatch (ArgumentException) { /* label already registered; reuse existing */ }","preventionTips":["Run transform registration exactly once per manager instance (idempotent init).","Check TransformLabelIsDefined before every DefineTransform call.","Use a single source of truth for transform label names."],"tags":["argument","duplicate","packaging","compound-file"],"backgroundTag":"file-already-exists","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"}