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

  1. Regenerate the C# code with a protoc version compatible with the Google.Protobuf runtime in use.
  2. Clean and rebuild the project to ensure descriptor bytes are correctly embedded.
  3. Verify deployment artifacts — the descriptor resource must not be truncated or altered post-build.
  4. 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

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


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)