stride3d/stride · error · ArgumentException

Unhandled value

Error message

Unhandled value: {dependency.Type}

What it means

PackageCollection.Find(dependency) resolves a PackageDependency to a package already present in the collection by switching on dependency.Type. Only Package and Project are handled; any other DependencyType value reaches the switch's throw arm, signaling an unhandled/unknown dependency type.

Solutions

  1. Set dependency.Type explicitly to DependencyType.Package or DependencyType.Project before calling Find.
  2. Inspect the dependency's origin (which package file serialized it) and fix or upgrade the library if the enum value comes from a newer format.
  3. Normalize unknown types to Package when you only need name/version matching, or filter them out before calling Find.
  4. Add a switch guard in caller code: only call Find for the two supported types and log/skip others.

Example fix

// before
var dep = new PackageDependency("MyGame"); // Type left at unhandled value
var pkg = packages.Find(dep); // throws

// after
dep.Type = DependencyType.Package;
var pkg = packages.Find(dep);
Defensive patterns

Strategy: type-guard

Validate before calling

if (dependency.Type is not (DependencyType.Package or DependencyType.Project))
    throw new NotSupportedException($"Unsupported dependency type: {dependency.Type}");
var pkg = packages.Find(dependency);

Type guard

bool IsSupportedDependencyType(PackageDependency d) =>
    d.Type is DependencyType.Package or DependencyType.Project;

Try / catch

try { var pkg = packages.Find(dep); }
catch (ArgumentException e) when (e.Message.Contains("Unhandled value"))
{ /* log the unknown DependencyType, skip or upgrade library */ }

Prevention

When it happens

Trigger: Calling packages.Find(dependency) (directly or via FindDependencies flows) with a PackageDependency whose Type is neither DependencyType.Package nor DependencyType.Project — e.g. a future/added enum member or a corrupted dependency record.

Common situations: Constructing PackageDependency without setting Type (relying on a default that is not handled); deserializing a dependency from a newer package format with an added enum value while running an older library version; typo-level misuse when building dependency lists programmatically.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/47ac6a64bd7b0e87. Report an issue: GitHub.

Appendix: source

Thrown at sources/assets/Stride.Core.Assets/PackageCollection.cs:69

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }

    /// <summary>
    /// Finds the a package already in this collection from the specified dependency.
    /// </summary>
    /// <param name="packageDependency">The package dependency.</param>
    /// <returns>Package.</returns>
    public Package? Find(Dependency dependency)
    {
        ArgumentNullException.ThrowIfNull(dependency);
        return dependency.Type switch
        {
            DependencyType.Package => Find(dependency.Name, new PackageVersionRange(dependency.Version)),
            DependencyType.Project => packages.FirstOrDefault(package => package.Meta.Name == dependency.Name && package.Container is SolutionProject),// Project versions might not be properly loaded so we check only by name
            _ => throw new ArgumentException($"Unhandled value: {dependency.Type}"),
        };
    }

    /// <summary>
    /// Finds the a package already in this collection from the specified dependency.
    /// </summary>
    /// <param name="packageDependency">The package dependency.</param>
    /// <returns>Package.</returns>
    public Package? Find(PackageDependency packageDependency)
    {
        ArgumentNullException.ThrowIfNull(packageDependency);
        return Find(packageDependency.Name, packageDependency.Version);
    }

    /// <summary>
    /// Finds a package with the specified name and <see cref="PackageVersionRange"/>.
    /// </summary>
    /// <param name="name">The name.</param>

View on GitHub (pinned to 96fad776d2)