{"record":{"id":"87332da8159de264","repo":"XINCGer/Unity3DTraining","slug":"messages-can-t-have-default-values","errorCode":null,"errorMessage":"Messages can't have default values.","messagePattern":"Messages can't have default values\\.","errorType":"validation","errorClass":"DescriptorValidationException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/FieldDescriptor.cs","lineNumber":331,"sourceCode":"                        fieldType = FieldType.Enum;\n                    }\n                    else\n                    {\n                        throw new DescriptorValidationException(this, \"\\\"\" + Proto.TypeName + \"\\\" is not a type.\");\n                    }\n                }\n\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)","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/FieldDescriptor.cs#L313-L349","documentation":"Proto3/message-typed fields cannot carry a default value; defaults only apply to scalar fields (proto2). During CrossLink, after resolving a message-typed field, a non-empty Proto.DefaultValue triggers DescriptorValidationException.","triggerScenarios":"A FieldDescriptorProto with Type = TYPE_MESSAGE and a non-empty DefaultValue string — e.g. hand-built descriptors, descriptors edited by tools, or protos written with invalid default_value on a message field.","commonSituations":"Porting proto2 scalar field configs onto message fields; code generators that emit default_value unconditionally; manual editing of descriptor sets.","solutions":["Remove the DefaultValue from the message-typed field's proto and regenerate.","Set message fields via initialization in code after parsing instead of via default_value.","Strip/ignore default_value for message fields when importing descriptors from external sources."],"exampleFix":"// before\nnew FieldDescriptorProto { Name = \"addr\", Type = TYPE_MESSAGE, TypeName = \"Address\", DefaultValue = \"\" }\n// after\nnew FieldDescriptorProto { Name = \"addr\", Type = TYPE_MESSAGE, TypeName = \"Address\" }","handlingStrategy":"validation","validationCode":"if (field.Proto.Type == FieldDescriptorProto.Types.Type.Message && field.Proto.DefaultValue != \"\")\n    throw new InvalidDataException(\"Message field \" + field.Name + \" must not have a default value\");","typeGuard":"bool HasNoMessageDefault(FieldDescriptorProto f) =>\n    f.Type != FieldDescriptorProto.Types.Type.Message || string.IsNullOrEmpty(f.DefaultValue);","tryCatchPattern":"try { descriptor = FileDescriptor.BuildFromByteStrings(data); }\ncatch (DescriptorValidationException ex) when (ex.Message == \"Messages can't have default values.\")\n{ log.LogError(ex, \"Remove default_value from message-typed fields\"); }","preventionTips":["Never set default_value on message or enum-typed fields.","Strip DefaultValue when sanitizing externally supplied descriptors.","Initialize message fields in application code instead of via descriptor defaults."],"tags":["protobuf","descriptor-validation","default-value"],"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"}