{"record":{"id":"dd4dacc1f9a76dab","repo":"XINCGer/Unity3DTraining","slug":"unknown-field","errorCode":null,"errorMessage":"Unknown field: ","messagePattern":"Unknown field: ","errorType":"validation","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":209,"sourceCode":"                    if (field.ContainingOneof != null)\n                    {\n                        if (seenOneofs == null)\n                        {\n                            seenOneofs = new HashSet<OneofDescriptor>();\n                        }\n                        if (!seenOneofs.Add(field.ContainingOneof))\n                        {\n                            throw new InvalidProtocolBufferException(\"Multiple values specified for oneof \" + field.ContainingOneof.Name);\n                        }\n                    }\n                    MergeField(message, field, tokenizer);\n                }\n                else\n                {\n                    // TODO: Is this what we want to do? If not, we'll need to skip the value,\n                    // which may be an object or array. (We might want to put code in the tokenizer\n                    // to do that.)\n                    throw new InvalidProtocolBufferException(\"Unknown field: \" + name);\n                }\n            }\n        }\n\n        private void MergeField(IMessage message, FieldDescriptor field, JsonTokenizer tokenizer)\n        {\n            var token = tokenizer.Next();\n            if (token.Type == JsonToken.TokenType.Null)\n            {\n                // Clear the field if we see a null token, unless it's for a singular field of type\n                // google.protobuf.Value.\n                // Note: different from Java API, which just ignores it.\n                // TODO: Bring it more in line? Discuss...\n                if (field.IsMap || field.IsRepeated || !IsGoogleProtobufValueField(field))\n                {\n                    field.Accessor.Clear(message);\n                    return;\n                }","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L191-L227","documentation":"By default JsonParser rejects JSON object keys that do not match any field in the message descriptor (neither JSON name nor original name), throwing InvalidProtocolBufferException with the unknown field's name. Proto JSON parsers are strict unless configured otherwise.","triggerScenarios":"Parsing JSON containing a property whose name matches no field — typos, camelCase/snake_case mismatches when the field was renamed, fields added in a newer schema version but parsed with older generated code, or leftover fields removed from the .proto.","commonSituations":"Schema drift between producer and consumer; renaming a proto field without preserving json_name; third-party services adding extra properties; forwarding client JSON payloads verbatim into a stricter message type.","solutions":["Fix or remove the unknown property from the JSON","Regenerate the C# code so descriptors match the producer's schema version","Align JSON naming with the descriptor (JsonParser matches json_name and original proto name; set json_name options if needed)","Add the missing field to the .proto if the producer legitimately sends it"],"exampleFix":"// before\n{ \"userName\": \"bob\" }  // proto field is 'username'\n// after\n{ \"username\": \"bob\" }","handlingStrategy":"try-catch","validationCode":"// Check all JSON keys exist in the schema before parsing (pseudo-validation of names)\nbool KnownField(string jsonKey) => descriptor.Fields.ByJsonName().ContainsKey(jsonKey) || descriptor.Fields.ByName().ContainsKey(jsonKey);","typeGuard":null,"tryCatchPattern":"try { return parser.Parse<T>(json); } catch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith(\"Unknown field:\")) { log.Error($\"JSON contains a field not in {typeof(T).Name}: {ex.Message}\"); throw new BadRequestException(ex.Message, ex); }","preventionTips":["Keep generated code in sync with the producer's .proto version","Preserve json_name when renaming proto fields","Log and monitor unknown-field errors to catch schema drift early"],"tags":["protobuf","json-parsing","unknown-field","schema-mismatch","strict-parsing"],"backgroundTag":"protobuf-unmarshal-failed","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"}