{"record":{"id":"6162d9ec86799c37","repo":"XINCGer/Unity3DTraining","slug":"typename-is-not-an-enum-type","errorCode":null,"errorMessage":"\"TypeName\" is not an enum type.","messagePattern":"\"TypeName\" is not an enum type\\.","errorType":"validation","errorClass":"DescriptorValidationException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/FieldDescriptor.cs","lineNumber":338,"sourceCode":"\n                if (fieldType == FieldType.Message)\n                {\n                    if (!(typeDescriptor is MessageDescriptor))\n                    {\n                        throw new DescriptorValidationException(this, \"\\\"\" + Proto.TypeName + \"\\\" is not a message type.\");\n                    }\n                    messageType = (MessageDescriptor)typeDescriptor;\n\n                    if (Proto.DefaultValue != \"\")\n                    {\n                        throw new DescriptorValidationException(this, \"Messages can't have default values.\");\n                    }\n                }\n                else if (fieldType == FieldType.Enum)\n                {\n                    if (!(typeDescriptor is EnumDescriptor))\n                    {\n                        throw new DescriptorValidationException(this, \"\\\"\" + Proto.TypeName + \"\\\" is not an enum type.\");\n                    }\n                    enumType = (EnumDescriptor)typeDescriptor;\n                }\n                else\n                {\n                    throw new DescriptorValidationException(this, \"Field with primitive type has type_name.\");\n                }\n            }\n            else\n            {\n                if (fieldType == FieldType.Message || fieldType == FieldType.Enum)\n                {\n                    throw new DescriptorValidationException(this, \"Field with message or enum type missing type_name.\");\n                }\n            }\n\n            // Note: no attempt to perform any default value parsing\n","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/FieldDescriptor.cs#L320-L356","documentation":"During CrossLink, if the field's resolved type is FieldType.Enum, the type_name must resolve to an EnumDescriptor. If the pool lookup returned a MessageDescriptor or other symbol, the field claims to be an enum but names a message, so DescriptorValidationException is thrown.","triggerScenarios":"A field with Type = TYPE_ENUM whose TypeName resolves to a message type — usually because the declared Type was edited (manually or by a tool) without updating TypeName, or the .proto changed 'enum X' to 'message X' and dependents were not regenerated.","commonSituations":"Converting an enum to a message in a shared .proto while generated descriptors elsewhere still say TYPE_ENUM; hand-built descriptors with swapped Type/TypeName pairs.","solutions":["Point TypeName at the actual enum, or set Type = TYPE_MESSAGE if a message is intended, then regenerate.","Regenerate all descriptor sets from the .proto sources to keep Type and TypeName consistent.","Before CrossLink, resolve TypeName and assert the symbol kind matches the declared field type."],"exampleFix":"// before (proto)\noptional MyMessage status = 1; // Type still TYPE_ENUM\n// after\noptional MyMessage status = 1; // with Type = TYPE_MESSAGE","handlingStrategy":"validation","validationCode":"if (field.Proto.Type == FieldDescriptorProto.Types.Type.Enum)\n{\n    var sym = pool.FindSymbol(field.Proto.TypeName);\n    if (!(sym is EnumDescriptor)) throw new InvalidDataException(field.Proto.TypeName + \" is not an enum\");\n}","typeGuard":"bool IsEnumField(FieldDescriptorProto f, DescriptorPool pool) =>\n    f.Type != FieldDescriptorProto.Types.Type.Enum || pool.FindSymbol(f.TypeName) is EnumDescriptor;","tryCatchPattern":"try { descriptor = FileDescriptor.BuildFromByteStrings(data); }\ncatch (DescriptorValidationException ex) when (ex.Message.Contains(\"is not an enum type\"))\n{ log.LogError(ex, \"Type/TypeName mismatch on enum field\"); }","preventionTips":["Keep Type = TYPE_ENUM only for fields naming actual enums.","Regenerate descriptors whenever a shared .proto changes a type's kind.","Validate Type against resolved symbol kind at descriptor import time."],"tags":["protobuf","descriptor-validation","type-mismatch"],"backgroundTag":"incompatible-source-type","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"}