{"record":{"id":"1eea6ce391854c14","repo":"MonoGame/MonoGame","slug":"vertex-channel-with-name-name-already-exists","errorCode":null,"errorMessage":"Vertex channel with name {name} already exists","messagePattern":"Vertex channel with name (.+?) already exists","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework.Content.Pipeline/Graphics/VertexChannelCollection.cs","lineNumber":229,"sourceCode":"            return _channels.IndexOf(item);\n        }\n\n        /// <summary>\n        /// Inserts a new vertex channel at the specified position.\n        /// </summary>\n        /// <typeparam name=\"ElementType\">Type of the new channel.</typeparam>\n        /// <param name=\"index\">Index for channel insertion.</param>\n        /// <param name=\"name\">Name of the new channel.</param>\n        /// <param name=\"channelData\">The new channel.</param>\n        /// <returns>The inserted vertex channel.</returns>\n        public VertexChannel<ElementType> Insert<ElementType>(int index, string name, IEnumerable<ElementType>? channelData)\n        {\n            if ((index < 0) || (index > _channels.Count))\n                throw new ArgumentOutOfRangeException(nameof(index));\n            ArgumentException.ThrowIfNullOrEmpty(name);\n            // Don't insert a channel with the same name\n            if (IndexOf(name) >= 0)\n                throw new ArgumentException(\"Vertex channel with name \" + name + \" already exists\");\n            var channel = new VertexChannel<ElementType>(name);\n            if (channelData != null)\n            {\n                // Insert the values from the enumerable into the channel\n                channel.InsertRange(0, channelData);\n                // Make sure we have the right number of vertices\n                if (channel.Count != _vertexContent.VertexCount)\n                    throw new ArgumentOutOfRangeException(nameof(channelData));\n            }\n            else\n            {\n                // Insert enough default values to fill the channel\n                channel.InsertRange(0, new ElementType[_vertexContent.VertexCount]);\n            }\n            _channels.Insert(index, channel);\n            return channel;\n        }\n","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework.Content.Pipeline/Graphics/VertexChannelCollection.cs#L211-L247","documentation":"Thrown by VertexChannelCollection.Insert<ElementType> when a channel with the specified name already exists. The collection enforces unique channel names — IndexOf(name) returns >= 0 for duplicates. This applies to both Insert(index, name, data) and Add(name, data) (which calls Insert at the end). Channel names follow encoded conventions (e.g., 'Normal0', 'TextureCoordinate0', 'Color1').","triggerScenarios":"Calling Channels.Add('Normal', data) when a channel named 'Normal' (or 'Normal0') already exists. Also triggered when inserting a channel whose name collides with an existing one after vertex data has been modified.","commonSituations":"Importing a model that already has normals and then adding normals again in a custom processor; calling Add multiple times in a loop without checking Contains(name); name encoding mismatches where 'Normal' and 'Normal0' are treated as different by user code but the collection sees a collision.","solutions":["Check Channels.Contains(name) or IndexOf(name) < 0 before calling Add or Insert","Remove the existing channel first with Channels.Remove(name) if you intend to replace it","Use ConvertChannelContent<T> to transform an existing channel in-place rather than adding a new one","Generate unique names using VertexChannelNames encoding helpers (e.g., VertexChannelNames.Normal(1))"],"exampleFix":"// before\nchannels.Add(VertexChannelNames.Normal(0), normals); // throws if 'Normal0' exists\n\n// after\nif (channels.Contains(VertexChannelNames.Normal(0)))\n    channels.Remove(VertexChannelNames.Normal(0));\nchannels.Add(VertexChannelNames.Normal(0), normals);","handlingStrategy":"validation","validationCode":"// Check for existing channel name before inserting\nif (vertexContent.Channels.Contains(name))\n    vertexContent.Channels.Remove(name); // or skip insertion\nvertexContent.Channels.Add<T>(name, data);","typeGuard":null,"tryCatchPattern":"try { channels.Add<T>(name, data); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"already exists\"))\n{ /* remove existing channel and retry, or skip */ }","preventionTips":["Call Channels.Contains(name) before Add or Insert","Use VertexChannelNames encoding helpers to generate standard unique names","Remove existing channels before re-adding with the same name"],"tags":["vertex","mesh","content-pipeline","monogame","validation"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}