{"record":{"id":"529329e70fa54832","repo":"XINCGer/Unity3DTraining","slug":"field-number-field-fieldnumber-has-already-been-u","errorCode":null,"errorMessage":"Field number {field.FieldNumber}has already been used in \"{field.ContainingType.FullName}\" by field \"{old.Name}\".","messagePattern":"Field number (.+?)has already been used in \"(.+?)\" by field \"(.+?)\"\\.","errorType":"validation","errorClass":"DescriptorValidationException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/DescriptorPool.cs","lineNumber":234,"sourceCode":"        internal EnumValueDescriptor FindEnumValueByNumber(EnumDescriptor enumDescriptor, int number)\n        {\n            EnumValueDescriptor ret;\n            enumValuesByNumber.TryGetValue(new DescriptorIntPair(enumDescriptor, number), out ret);\n            return ret;\n        }\n\n        /// <summary>\n        /// Adds a field to the fieldsByNumber table.\n        /// </summary>\n        /// <exception cref=\"DescriptorValidationException\">A field with the same\n        /// containing type and number already exists.</exception>\n        internal void AddFieldByNumber(FieldDescriptor field)\n        {\n            DescriptorIntPair key = new DescriptorIntPair(field.ContainingType, field.FieldNumber);\n            FieldDescriptor old;\n            if (fieldsByNumber.TryGetValue(key, out old))\n            {\n                throw new DescriptorValidationException(field, \"Field number \" + field.FieldNumber +\n                                                               \"has already been used in \\\"\" +\n                                                               field.ContainingType.FullName +\n                                                               \"\\\" by field \\\"\" + old.Name + \"\\\".\");\n            }\n            fieldsByNumber[key] = field;\n        }\n\n        /// <summary>\n        /// Adds an enum value to the enumValuesByNumber table. If an enum value\n        /// with the same type and number already exists, this method does nothing.\n        /// (This is allowed; the first value defined with the number takes precedence.)\n        /// </summary>\n        internal void AddEnumValueByNumber(EnumValueDescriptor enumValue)\n        {\n            DescriptorIntPair key = new DescriptorIntPair(enumValue.EnumDescriptor, enumValue.Number);\n            if (!enumValuesByNumber.ContainsKey(key))\n            {\n                enumValuesByNumber[key] = enumValue;","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/DescriptorPool.cs#L216-L252","documentation":"DescriptorPool.AddFieldByNumber throws DescriptorValidationException when two fields within the same message type are assigned the same field number. Field numbers are the wire-format identity of a field, so duplicates within one message are ambiguous and forbidden. (The message text is missing a space after the number — a cosmetic quirk of this port.)","triggerScenarios":"Building a FileDescriptor where two FieldDescriptorProto entries of the same DescriptorProto share a Number — e.g. hand-constructed descriptors adding field 1 twice, a duplicated field entry in a serialized FileDescriptorSet, or generated descriptors from a broken custom codegen.","commonSituations":"Programmatic schema builders appending fields with auto-incremented numbers that reset or collide; copying an existing field and forgetting to change its number; merging schemas from branches where two developers picked the same field number.","solutions":["Change one of the conflicting fields' Number so every field in the message has a unique number.","When adding fields programmatically, track the highest used number per message and allocate the next free one.","Fix the source .proto (two fields with the same number) and regenerate with protoc.","Never reuse/remove numbers on the wire without reserving them (reserved ranges) to avoid conflicts in evolving schemas."],"exampleFix":"// before\nnew FieldDescriptorProto { Name = \"a\", Number = 1, ... },\nnew FieldDescriptorProto { Name = \"b\", Number = 1, ... } // duplicate\n// after\nnew FieldDescriptorProto { Name = \"a\", Number = 1, ... },\nnew FieldDescriptorProto { Name = \"b\", Number = 2, ... }","handlingStrategy":"validation","validationCode":"static void AssertUniqueFieldNumbers(DescriptorProto msg)\n{\n    var seen = new HashSet<int>();\n    foreach (var f in msg.Fields)\n        if (!seen.Add(f.Number))\n            throw new InvalidOperationException($\"Duplicate field number {f.Number} in {msg.Name}\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var fd = FileDescriptor.BuildFromByteString(bytes, dependencies);\n}\ncatch (DescriptorValidationException ex) when (ex.Message.Contains(\"has already been used in\"))\n{\n    // renumber the duplicated field and rebuild\n}","preventionTips":["Use a per-message max-number allocator when building fields programmatically","Reserve field numbers in evolving schemas to prevent collisions","Run buf lint / protoc validation in CI before building descriptors"],"tags":["protobuf","descriptor","field-number","csharp"],"backgroundTag":"schema-validation-failed","analyzedSha":"016f98412ea5e11756b286736f479b66ab6216d5","analyzedAt":"2026-09-12T01:08:58.711Z","contentChangedAt":"2026-09-12T01:08:58.711Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}