{"record":{"id":"8b069c3ba06b79b5","repo":"XINCGer/Unity3DTraining","slug":"field-with-primitive-type-has-type-name","errorCode":null,"errorMessage":"Field with primitive type has type_name.","messagePattern":"Field with primitive type has type_name\\.","errorType":"validation","errorClass":"DescriptorValidationException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/FieldDescriptor.cs","lineNumber":344,"sourceCode":"                    }\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\n            File.DescriptorPool.AddFieldByNumber(this);\n\n            if (ContainingType != null && ContainingType.Proto.Options != null && ContainingType.Proto.Options.MessageSetWireFormat)\n            {\n                throw new DescriptorValidationException(this, \"MessageSet format is not supported.\");\n            }","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/FieldDescriptor.cs#L326-L362","documentation":"Fields with a primitive/scalar type (numbers, bool, string, bytes) must not set type_name; only message and enum fields use it. During CrossLink, if a field has no inline type resolution but carries a TypeName and its field type is scalar, DescriptorValidationException is thrown.","triggerScenarios":"A FieldDescriptorProto with a scalar Type (e.g. TYPE_INT32) AND a non-empty TypeName — e.g. hand-built protos that set both, or generated descriptors where type_name was not cleared when the type was changed to a scalar.","commonSituations":"Changing a field from a message to a scalar in code without clearing TypeName; custom code generators emitting TypeName for all fields; descriptor manipulation tools that copy field templates.","solutions":["Clear Proto.TypeName for scalar-typed fields before building the descriptor set.","Regenerate descriptors from the .proto so protoc emits type_name only for message/enum fields.","Sanitize imported FileDescriptorProtos: drop type_name whenever Type is a primitive type."],"exampleFix":"// before\nnew FieldDescriptorProto { Name = \"count\", Type = TYPE_INT32, TypeName = \"MyApp.Count\" }\n// after\nnew FieldDescriptorProto { Name = \"count\", Type = TYPE_INT32 }","handlingStrategy":"validation","validationCode":"var scalar = field.Proto.Type is FieldDescriptorProto.Types.Type.Int32 or FieldDescriptorProto.Types.Type.Int64 or FieldDescriptorProto.Types.Type.Uint32 or FieldDescriptorProto.Types.Type.Uint64 or FieldDescriptorProto.Types.Type.Float or FieldDescriptorProto.Types.Type.Double or FieldDescriptorProto.Types.Type.Bool or FieldDescriptorProto.Types.Type.String or FieldDescriptorProto.Types.Type.Bytes;\nif (scalar && field.Proto.TypeName != \"\")\n    throw new InvalidDataException(\"Scalar field \" + field.Name + \" must not set type_name\");","typeGuard":"bool TypeNameAllowed(FieldDescriptorProto f) =>\n    f.Type == FieldDescriptorProto.Types.Type.Message || f.Type == FieldDescriptorProto.Types.Type.Enum || f.TypeName == \"\";","tryCatchPattern":"try { descriptor = FileDescriptor.BuildFromByteStrings(data); }\ncatch (DescriptorValidationException ex) when (ex.Message == \"Field with primitive type has type_name.\")\n{ log.LogError(ex, \"Clear type_name on scalar fields\"); }","preventionTips":["Clear TypeName whenever changing a field's type to a scalar in descriptor-building code.","Let protoc emit descriptors rather than hand-assembling FieldDescriptorProtos.","Sanitize imported descriptor sets: drop type_name for all primitive types."],"tags":["protobuf","descriptor-validation","type-mismatch"],"backgroundTag":"invalid-config-value","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"}