XINCGer/Unity3DTraining · error · ArgumentException
Invalid embedded descriptor for
Error message
Invalid embedded descriptor for "{proto.Name}". What it means
If building the file descriptor from embedded data raises a DescriptorValidationException, FromGeneratedCode wraps it in an ArgumentException naming the proto file. The root cause is any descriptor validation failure (bad field types, missing types, dependency mismatch, etc.) inside the embedded descriptor of generated code.
Solutions
- Inspect the inner DescriptorValidationException (ArgumentException.InnerException) for the real cause.
- Regenerate ALL dependent .cs files from the current .proto files in one protoc run.
- Ensure every imported file's descriptor is passed in the dependencies argument.
- Diff the embedded descriptor bytes against a freshly generated descriptor to find the divergence.
Example fix
// before
try { var fd = FileDescriptor.FromGeneratedCode(data, deps, msgs); } catch (ArgumentException e) { /* only outer message visible */ }
// after
catch (ArgumentException e) { throw new InvalidOperationException("Root cause: " + e.InnerException?.Message, e); } // surface real validation error Defensive patterns
Strategy: try-catch
Try / catch
try { FromGeneratedCode(...); } catch (ArgumentException e) { var root = e.InnerException as DescriptorValidationException; log.LogError($"Descriptor for {root?.Descriptor?.Name}: {root?.Message}"); } Prevention
- Always inspect InnerException to find the underlying validation failure.
- Regenerate the full descriptor set and all generated files in one run.
- Validate descriptors in CI before shipping assemblies.
When it happens
Trigger: FromGeneratedCode where CrossLink or validation fails: missing type_name, unknown dependency with allowUnknownDependencies=false mismatch, dependency count mismatch, or referencing a type not present in the descriptor set.
Common situations: Mixed generated files from different schema versions; a generated file's dependencies array missing an imported descriptor; hand-edited generated code; descriptor bytes generated from a .proto inconsistent with its imports.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Field with message or enum type missing type_name.
- Invalid public dependency
- Dependencies passed to FileDescriptor.BuildFrom() don't…
- No such field number
- Invalid map field:
AI-assisted analysis of XINCGer/Unity3DTraining@016f98412e (2026-09-12).
Data as JSON: /api/errors/cec7629cbc25ad31.
Report an issue: GitHub.
Appendix: source
Thrown at NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/FileDescriptor.cs:327
FileDescriptorProto proto;
try
{
proto = FileDescriptorProto.Parser.ParseFrom(descriptorData);
}
catch (InvalidProtocolBufferException e)
{
throw new ArgumentException("Failed to parse protocol buffer descriptor for generated code.", e);
}
try
{
// When building descriptors for generated code, we allow unknown
// dependencies by default.
return BuildFrom(ByteString.CopyFrom(descriptorData), proto, dependencies, true, generatedCodeInfo);
}
catch (DescriptorValidationException e)
{
throw new ArgumentException("Invalid embedded descriptor for \"" + proto.Name + "\".", e);
}
}
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents this instance.
/// </returns>
public override string ToString()
{
return "FileDescriptor for " + Name;
}
/// <summary>
/// Returns the file descriptor for descriptor.proto.
/// </summary>
/// <remarks>View on GitHub (pinned to 016f98412e)