{"record":{"id":"2f776d9358dd8db8","repo":"XINCGer/Unity3DTraining","slug":"failed-to-parse-protocol-buffer-descriptor-for-gen","errorCode":null,"errorMessage":"Failed to parse protocol buffer descriptor for generated code.","messagePattern":"Failed to parse protocol buffer descriptor for generated code\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/FileDescriptor.cs","lineNumber":316,"sourceCode":"            FileDescriptorProto proto;\n            try\n            {\n                proto = FileDescriptorProto.Parser.ParseFrom(descriptorData);\n            }\n            catch (InvalidProtocolBufferException e)\n            {\n                throw new ArgumentException(\"Failed to parse protocol buffer descriptor for generated code.\", e);\n            }","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/FileDescriptor.cs#L298-L334","documentation":"FromGeneratedCode — the entry point protoc-generated C# code uses to build a FileDescriptor from serialized descriptor bytes — wraps InvalidProtocolBufferException in this ArgumentException when the embedded FileDescriptorProto cannot be parsed. It fires at type-initialization time when the descriptorData byte array passed by generated code is corrupt, truncated, or was produced by an incompatible protoc/runtime version.","triggerScenarios":"Static initialization of a generated message/descriptor class whose embedded descriptorData fails FileDescriptorProto.Parser.ParseFrom — typically from binary corruption, bad resource embedding, or a protoc/Google.Protobuf version mismatch.","commonSituations":"Regenerating .cs files with a newer protoc while the runtime Google.Protobuf DLL is older (or vice versa); a build/deploy step that truncates or mangles the embedded descriptor resource; manually hand-crafted or edited descriptor byte arrays.","solutions":["Regenerate the C# code with a protoc version compatible with the Google.Protobuf runtime in use.","Clean and rebuild the project to ensure descriptor bytes are correctly embedded.","Verify deployment artifacts — the descriptor resource must not be truncated or altered post-build.","Update the Google.Protobuf NuGet/plugin so runtime and generator versions align."],"exampleFix":"Regenerate the code with protoc matching the Google.Protobuf package version (e.g. protoc 3.x with Google.Protobuf 3.x) and rebuild so descriptorData is re-embedded.","handlingStrategy":"fallback","validationCode":"bool DescriptorParses(byte[] data) { try { FileDescriptorProto.Parser.ParseFrom(data); return true; } catch (InvalidProtocolBufferException) { return false; } }","typeGuard":null,"tryCatchPattern":"try { FromGeneratedCode(data, deps, msgs); } catch (ArgumentException e) when (e.Message.Contains(\"Failed to parse\")) { log.LogError(\"Embedded descriptor bytes corrupt — regenerate code\", e); }","preventionTips":["Pin protoc and Google.Protobuf runtime to compatible versions (e.g. via a version-pinned build script).","Regenerate all protobuf code as part of the same build that updates the runtime package.","Fail fast in CI by touching each generated descriptor type in a smoke test."],"tags":[],"backgroundTag":null,"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"}