XINCGer/Unity3DTraining · error · DescriptorValidationException

Invalid public dependency

Error message

Invalid public dependency: {name}

What it means

After resolving a public dependency index to a dependency name, DeterminePublicDependencies looks it up in the nameToFileMap. If the named file has no known FileDescriptor and allowUnknownDependencies is false, a DescriptorValidationException is thrown. Unknown dependencies can only be tolerated when explicitly allowed (as generated code does).

Solutions

  1. Pass the FileDescriptor for every imported file in the dependencies argument to BuildFrom, in the same order as proto.Dependency.
  2. Add descriptors for the well-known types (Google.Protobuf.Reflection includes them via DescriptorReflection or generated files).
  3. Regenerate code so descriptor data, dependencies, and imports agree.
  4. Use allowUnknownDependencies=true only if the unknown import's types are genuinely unused.

Example fix

// before
FileDescriptor.BuildFrom(data, proto, new FileDescriptor[0], false, null); // proto imports timestamp.proto
// after
FileDescriptor.BuildFrom(data, proto, new[] { TimestampReflection.Descriptor }, false, null);
Defensive patterns

Strategy: try-catch

Validate before calling

bool AllDepsKnown(FileDescriptorProto p, IDictionary<string,FileDescriptor> map) => p.Dependency.All(d => map.ContainsKey(d));

Try / catch

try { BuildFrom(data, proto, deps, false, null); } catch (DescriptorValidationException e) when (e.Message.StartsWith("Invalid public dependency:")) { log.LogError($"Missing descriptor for import: {e.Message}"); }

Prevention

When it happens

Trigger: FileDescriptor.BuildFrom called with allowUnknownDependencies=false while the FileDescriptorProto declares a dependency (or public dependency) whose FileDescriptor was not supplied in the dependencies collection — e.g. importing 'google/protobuf/timestamp.proto' without passing its descriptor.

Common situations: Missing well-known-type descriptors (timestamp, duration, wrappers, any); forgetting to add an imported .proto's descriptor to the dependencies array; descriptors regenerated with a new import but callers not updated.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

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

            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);
        }

        /// <value>
        /// The descriptor in its protocol message representation.
        /// </value>
        internal readonly FileDescriptorProto Proto;

        /// <value>
        /// The file name.

View on GitHub (pinned to 016f98412e)