dotnet/wpf · error · ArgumentException

Transform label name is already in use.

Error message

Transform label name is already in use.

What it means

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.

Solutions

  1. Check TransformLabelIsDefined(label) before calling DefineTransform and skip registration if it returns true.
  2. Guard initialization so DefineTransform runs only once per DataSpaceManager lifetime.
  3. Generate unique labels (append a counter or GUID) when creating transform names programmatically.
  4. Catch ArgumentException with SR.TransformLabelInUse and reuse the existing transform instead of redefining it.

Example fix

// before
manager.DefineTransform("CompressionTransform", factory); // second call throws
// after
if (!manager.TransformLabelIsDefined("CompressionTransform"))
    manager.DefineTransform("CompressionTransform", factory);
Defensive patterns

Strategy: validation

Validate before calling

if (!manager.TransformLabelIsDefined(label))
    manager.DefineTransform(label, factory);

Try / catch

try { manager.DefineTransform(label, factory); }
catch (ArgumentException) { /* label already registered; reuse existing */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/cf57b88f2a1a8f04. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/DataSpaceManager.cs:913

    /// </summary>
    /// <param name="transformClassName">Transform identification string</param>
    /// <param name="newTransformLabel">Label to use for new transform</param>
    internal void DefineTransform(string transformClassName, string newTransformLabel )
    {
        CheckDisposedStatus();

        // Check to see if transform name is obviously invalid
        CU.CheckStringAgainstNullAndEmpty( transformClassName, "Transform identifier name" );

        // Check to see if transform name is valid
        CU.CheckStringAgainstNullAndEmpty( newTransformLabel, "Transform label" );

        // Given transform name must not be a reserved string
        CU.CheckStringAgainstReservedName( newTransformLabel, "Transform label" );

        // Can't re-use an existing transform name
        if( TransformLabelIsDefined( newTransformLabel ) )
            throw new ArgumentException(
                SR.TransformLabelInUse);

        // Create class the transform object will use to communicate to us
        TransformEnvironment transformEnvironment = new TransformEnvironment( this, newTransformLabel );

        // Create a TransformInstance object to represent this transform instance.
        TransformInstance newTransform = new TransformInstance(
            TransformIdentifierTypes_PredefinedTransformName,
            transformClassName,
            null,
            transformEnvironment );

        SetTransformDefinition( newTransformLabel, newTransform );

        // Create the transform object
        IDataTransform transformObject = InstantiateDataTransformObject(
                                                    TransformIdentifierTypes_PredefinedTransformName,
                                                    transformClassName,

View on GitHub (pinned to 81131a70a4)