XINCGer/Unity3DTraining · error · ArgumentException
Failed to parse protocol buffer descriptor for generated…
Error message
Failed to parse protocol buffer descriptor for generated code.
What it means
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.
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.
Example fix
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.
Defensive patterns
Strategy: fallback
Validate before calling
bool DescriptorParses(byte[] data) { try { FileDescriptorProto.Parser.ParseFrom(data); return true; } catch (InvalidProtocolBufferException) { return false; } } Try / catch
try { FromGeneratedCode(data, deps, msgs); } catch (ArgumentException e) when (e.Message.Contains("Failed to parse")) { log.LogError("Embedded descriptor bytes corrupt — regenerate code", e); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of XINCGer/Unity3DTraining@016f98412e (2026-09-12).
Data as JSON: /api/errors/2f776d9358dd8db8.
Report an issue: GitHub.
Appendix: source
Thrown at NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/FileDescriptor.cs:316
FileDescriptorProto proto;
try
{
proto = FileDescriptorProto.Parser.ParseFrom(descriptorData);
}
catch (InvalidProtocolBufferException e)
{
throw new ArgumentException("Failed to parse protocol buffer descriptor for generated code.", e);
}View on GitHub (pinned to 016f98412e)