{"record":{"id":"09164cd4d23e0814","repo":"XINCGer/Unity3DTraining","slug":"enums-must-contain-at-least-one-value","errorCode":null,"errorMessage":"Enums must contain at least one value.","messagePattern":"Enums must contain at least one value\\.","errorType":"validation","errorClass":"DescriptorValidationException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/EnumDescriptor.cs","lineNumber":59,"sourceCode":"    public sealed class EnumDescriptor : DescriptorBase\n    {\n        private readonly EnumDescriptorProto proto;\n        private readonly MessageDescriptor containingType;\n        private readonly IList<EnumValueDescriptor> values;\n        private readonly Type clrType;\n\n        internal EnumDescriptor(EnumDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, Type clrType)\n            : base(file, file.ComputeFullName(parent, proto.Name), index)\n        {\n            this.proto = proto;\n            this.clrType = clrType;\n            containingType = parent;\n\n            if (proto.Value.Count == 0)\n            {\n                // We cannot allow enums with no values because this would mean there\n                // would be no valid default value for fields of this type.\n                throw new DescriptorValidationException(this, \"Enums must contain at least one value.\");\n            }\n\n            values = DescriptorUtil.ConvertAndMakeReadOnly(proto.Value,\n                                                           (value, i) => new EnumValueDescriptor(value, file, this, i));\n\n            File.DescriptorPool.AddSymbol(this);\n        }\n\n        internal EnumDescriptorProto Proto { get { return proto; } }\n\n        /// <summary>\n        /// The brief name of the descriptor's target.\n        /// </summary>\n        public override string Name { get { return proto.Name; } }\n\n        /// <summary>\n        /// The CLR type for this enum. For generated code, this will be a CLR enum type.\n        /// </summary>","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/EnumDescriptor.cs#L41-L77","documentation":"EnumDescriptor construction throws DescriptorValidationException when an EnumDescriptorProto contains zero values. Protobuf requires every enum to declare at least one value because fields of that enum type need a valid default value (the first declared value, which must be 0 in proto3).","triggerScenarios":"Building a FileDescriptor from an EnumDescriptorProto with an empty Value collection — e.g. new EnumDescriptorProto { Name = \"E\" } with no values added, a serialized FileDescriptorSet whose enum has no EnumValueProto entries, or a custom codegen emitting empty enums.","commonSituations":"Dynamically generating proto descriptors and forgetting to seed a default enum value; tooling stripping all enum values during schema transformation; tests constructing minimal descriptor scaffolding without populating values.","solutions":["Add at least one enum value, conventionally a zero-valued default (proto3 requires the first value to have number 0).","If building descriptors programmatically, add an EnumValueProto entry before building the FileDescriptor.","Inspect the serialized descriptor set for enums with empty 'value' lists and fix the producer tooling.","Validate descriptor protos before building (assert proto.Value.Count > 0 for every enum)."],"exampleFix":"// before\nvar e = new EnumDescriptorProto { Name = \"Status\" }; // no values\nfileProto.EnumTypes.Add(e);\n// after\nvar e = new EnumDescriptorProto\n{\n    Name = \"Status\",\n    Values = { new EnumValueDescriptorProto { Name = \"STATUS_UNKNOWN\", Number = 0 } }\n};\nfileProto.EnumTypes.Add(e);","handlingStrategy":"validation","validationCode":"static void AssertEnumsHaveValues(FileDescriptorProto file)\n{\n    foreach (var e in file.EnumTypes)\n        if (e.Values.Count == 0)\n            throw new InvalidOperationException($\"Enum {e.Name} has no values\");\n}","typeGuard":"bool HasValues(EnumDescriptorProto e) => e.Value.Count > 0;","tryCatchPattern":"try\n{\n    var fd = FileDescriptor.BuildFromByteString(bytes, dependencies);\n}\ncatch (DescriptorValidationException ex) when (ex.Message.Contains(\"at least one value\"))\n{\n    // reject the descriptor set / add a default zero value and rebuild\n}","preventionTips":["Always define a zero-valued default enum value first (proto3 requirement)","Validate descriptor protos before building","When generating enums dynamically, seed a UNKNOWN = 0 value"],"tags":["protobuf","descriptor","enum","csharp"],"backgroundTag":"empty-required-field","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"}