XINCGer/Unity3DTraining · error · DescriptorValidationException

Invalid public dependency index.

Error message

Invalid public dependency index.

What it means

DeterminePublicDependencies maps each index in FileDescriptorProto.PublicDependency to an entry of the Dependency list. An index that is negative or >= Dependency.Count cannot be resolved, so a DescriptorValidationException is thrown. This indicates a corrupt or malformed descriptor.

Solutions

  1. Regenerate the descriptor with protoc so public_dependency indices are consistent with the dependency list.
  2. If constructing FileDescriptorProto manually, ensure every PublicDependency index is within [0, proto.Dependency.Count).
  3. Validate the proto before BuildFrom: check PublicDependency.All(i => i >= 0 && i < Dependency.Count).
  4. Inspect and re-serialize the descriptor bytes if corruption is suspected.

Example fix

// before
proto.PublicDependency.Add(5); // but proto.Dependency has only 2 entries
// after
proto.PublicDependency.Add(1); // valid index into proto.Dependency
Defensive patterns

Strategy: validation

Validate before calling

bool PublicDepsValid(FileDescriptorProto p) => p.PublicDependency.All(i => i >= 0 && i < p.Dependency.Count);

Try / catch

try { BuildFrom(...); } catch (DescriptorValidationException e) when (e.Message == "Invalid public dependency index.") { log.LogError("Corrupt descriptor: public_dependency out of range"); }

Prevention

When it happens

Trigger: Building a FileDescriptor from a FileDescriptorProto whose public_dependency entries reference indices outside the dependency list — typically after manual construction or corruption of the serialized descriptor bytes.

Common situations: Descriptor bytes hand-assembled or post-processed incorrectly; descriptors mutated by tooling; bad serialization from a third-party generator.

Related errors


AI-assisted analysis of XINCGer/Unity3DTraining@016f98412e (2026-09-12). Data as JSON: /api/errors/5f3e93b09466ec08. Report an issue: GitHub.

Appendix: source

Thrown at NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/FileDescriptor.cs:103

        /// <summary>
        /// Extracts public dependencies from direct dependencies. This is a static method despite its
        /// first parameter, as the value we're in the middle of constructing is only used for exceptions.
        /// </summary>
        private static IList<FileDescriptor> DeterminePublicDependencies(FileDescriptor @this, FileDescriptorProto proto, FileDescriptor[] dependencies, bool allowUnknownDependencies)
        {
            var nameToFileMap = new Dictionary<string, FileDescriptor>();
            foreach (var file in dependencies)
            {
                nameToFileMap[file.Name] = file;
            }
            var publicDependencies = new List<FileDescriptor>();
            for (int i = 0; i < proto.PublicDependency.Count; i++)
            {
                int index = proto.PublicDependency[i];
                if (index < 0 || index >= proto.Dependency.Count)
                {
                    throw new DescriptorValidationException(@this, "Invalid public dependency index.");
                }
                string name = proto.Dependency[index];
                FileDescriptor file = nameToFileMap[name];
                if (file == null)
                {
                    if (!allowUnknownDependencies)
                    {
                        throw new DescriptorValidationException(@this, "Invalid public dependency: " + name);
                    }
                    // Ignore unknown dependencies.
                }
                else
                {
                    publicDependencies.Add(file);
                }
            }
            return new ReadOnlyCollection<FileDescriptor>(publicDependencies);
        }

View on GitHub (pinned to 016f98412e)