{"record":{"id":"3468f9bd34c1267c","repo":"XINCGer/Unity3DTraining","slug":"no-such-field-name","errorCode":null,"errorMessage":"No such field name","messagePattern":"No such field name","errorType":"exception","errorClass":"KeyNotFoundException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/MessageDescriptor.cs","lineNumber":344,"sourceCode":"                    return fieldDescriptor;\n                }\n            }\n\n            /// <summary>\n            /// Retrieves the descriptor for the field with the given name.\n            /// </summary>\n            /// <param name=\"name\">Name of the field to retrieve the descriptor for</param>\n            /// <returns>The descriptor for the given field</returns>\n            /// <exception cref=\"KeyNotFoundException\">The message descriptor does not contain a field\n            /// with the given name</exception>\n            public FieldDescriptor this[string name]\n            {\n                get\n                {\n                    var fieldDescriptor = messageDescriptor.FindFieldByName(name);\n                    if (fieldDescriptor == null)\n                    {\n                        throw new KeyNotFoundException(\"No such field name\");\n                    }\n                    return fieldDescriptor;\n                }\n            }\n        }\n    }\n}\n","sourceCodeStart":326,"sourceCodeEnd":352,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/MessageDescriptor.cs#L326-L352","documentation":"MessageDescriptor's FieldCollection indexer (accessed via descriptor.Fields[name]) throws KeyNotFoundException when the field name does not exist in the message's protobuf schema. Google.Protobuf uses this instead of returning null so callers fail fast on typos. The name lookup is case-sensitive against the .proto field names.","triggerScenarios":"Calling messageDescriptor.Fields[\"someField\"] where the field is not declared in the .proto message, using the JSON/camelCase name when only the proto snake_case name (or vice versa) exists, or a misspelled field name.","commonSituations":"Hand-written reflection code building message accessors from string names loaded from config; schema drift where a field was renamed or removed in a newer .proto version while old code still asks for it.","solutions":["Check the field exists first: if (desc.Fields.ByJsonName(name) != null) or wrap the indexer access in try/catch (KeyNotFoundException).","Verify the exact .proto field name (snake_case) vs the JSON name (camelCase) and use the correct one.","Confirm the descriptor comes from the same FileDescriptor/schema version as the code expecting the field."],"exampleFix":"// before\nvar fd = msgDesc.Fields[\"userId\"];\n// after\nvar fd = msgDesc.FindFieldByName(\"user_id\") ?? msgDesc.FindFieldByName(\"userId\");\nif (fd == null) { /* handle unknown field */ }","handlingStrategy":"validation","validationCode":"var fd = msgDesc.FindFieldByName(name) ?? msgDesc.Fields.ByJsonName(name);\nif (fd == null) throw new InvalidOperationException($\"Unknown field '{name}' on {msgDesc.FullName}\");","typeGuard":null,"tryCatchPattern":"try { fd = msgDesc.Fields[name]; } catch (KeyNotFoundException ex) { log.Warn($\"Unknown proto field '{name}'\"); fd = null; }","preventionTips":["Prefer FindFieldByName/ByJsonName which return null over the throwing indexer.","Keep field-name strings in constants generated from the schema, not ad-hoc literals.","Add integration checks after schema changes to verify all referenced field names still exist."],"tags":["protobuf","reflection","key-not-found"],"backgroundTag":"record-not-found","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"}