{"record":{"id":"e7217357a08551e8","repo":"XINCGer/Unity3DTraining","slug":"invalid-field-type-for-map","errorCode":null,"errorMessage":"Invalid field type for map: ","messagePattern":"Invalid field type for map: ","errorType":"validation","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":596,"sourceCode":"                    throw new InvalidProtocolBufferException(\"Invalid string for bool map key: \" + keyText);\n                case FieldType.String:\n                    return keyText;\n                case FieldType.Int32:\n                case FieldType.SInt32:\n                case FieldType.SFixed32:\n                    return ParseNumericString<int>(keyText, int.Parse);\n                case FieldType.UInt32:\n                case FieldType.Fixed32:\n                    return ParseNumericString<uint>(keyText, uint.Parse);\n                case FieldType.Int64:\n                case FieldType.SInt64:\n                case FieldType.SFixed64:\n                    return ParseNumericString<long>(keyText, long.Parse);\n                case FieldType.UInt64:\n                case FieldType.Fixed64:\n                    return ParseNumericString<ulong>(keyText, ulong.Parse);\n                default:\n                    throw new InvalidProtocolBufferException(\"Invalid field type for map: \" + field.FieldType);\n            }\n        }\n\n        private static object ParseSingleNumberValue(FieldDescriptor field, JsonToken token)\n        {\n            double value = token.NumberValue;\n            checked\n            {\n                try\n                {\n                    switch (field.FieldType)\n                    {\n                        case FieldType.Int32:\n                        case FieldType.SInt32:\n                        case FieldType.SFixed32:\n                            CheckInteger(value);\n                            return (int)value;\n                        case FieldType.UInt32:","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L578-L614","documentation":"ParseMapKey handles all legal protobuf map key field types (bool, string, and integer types). If the map's key field is any other type (e.g. float, double, bytes — which are disallowed as map keys in proto anyway), the parser falls through to the default case and throws this InvalidProtocolBufferException.","triggerScenarios":"Parsing JSON for a generated map type whose key field descriptor has an unsupported FieldType — typically from a corrupted/desynced descriptor set or a descriptor built outside the standard proto map-key constraints.","commonSituations":"Reflectively constructed descriptors or generated code/descriptor mismatch after regenerating protos with a different compiler version; dynamic messages built with invalid key types.","solutions":["Regenerate code from the .proto ensuring map keys are only integral, bool, or string types.","Verify the descriptor source matches the generated code version (rebuild both from the same .proto files).","If using dynamic messages, validate the map field's key FieldDescriptor.FieldType before parsing."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate map key field type on the generated descriptor\nvar keyType = MyMessage.Descriptor.FindFieldByName(\"myMap\").MessageType.FindFieldByName(\"key\").FieldType;\nbool ok = keyType == FieldType.Bool || keyType == FieldType.String ||\n          (keyType >= FieldType.Int32 && keyType <= FieldType.Fixed64);\nif (!ok) throw new Exception($\"Unsupported map key type: {keyType}\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var msg = parser.Parse<T>(json);\n}\ncatch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith(\"Invalid field type for map:\"))\n{\n    // indicates generated code/descriptor mismatch; regenerate code\n}","preventionTips":["Only use proto-legal map key types (integer, bool, string) in .proto files","Regenerate client code and descriptors from the same .proto version","Avoid hand-constructing map descriptors in dynamic message scenarios"],"tags":["protobuf","json-parsing","map-key","field-type"],"backgroundTag":"unsupported-operation","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"}