stride3d/stride · error · ArgumentException

Type [ ] must be assignable to Asset or be a Package

Error message

Type [{0}] must be assignable to Asset or be a Package

What it means

AssetRegistry's validation helper throws ArgumentException when the given assetType is not assignable to Asset and throwException is true. This variant checks only Asset assignability (no Package allowance), so types used for non-asset registries are rejected.

Solutions

  1. Make the registered type derive from Stride.Core.Assets.Asset.
  2. Use the overload that accepts Package types if you intend to register a Package.
  3. Pass throwException:false if you only want a boolean validity check instead of an exception.

Example fix

// before
public class MyThing { } // not an Asset
AssetRegistry.CheckAssetType(typeof(MyThing), true);
// after
public class MyThing : Asset { }
Defensive patterns

Strategy: validation

Validate before calling

if (!typeof(Asset).IsAssignableFrom(assetType)) throw new ArgumentException($"{assetType} must derive from Asset");

Type guard

bool IsAssetType(Type t) => typeof(Asset).IsAssignableFrom(t);

Try / catch

try { AssetRegistry.CheckAssetType(assetType, true); } catch (ArgumentException ex) when (ex.Message.Contains("assignable to Asset")) { log.Error($"{assetType} is not an Asset type"); }

Prevention

When it happens

Trigger: Registering/validating a type via the Asset-only overload where typeof(Asset).IsAssignableFrom(assetType) is false, e.g. passing a Package type or an unrelated class.

Common situations: Passing typeof(Package) to the strict Asset-only validation by mistake; a typo'd or refactored type no longer derives from Asset; plugin authors registering plain POCOs as assets.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at sources/assets/Stride.Core.Assets/AssetRegistry.cs:859

                RegisteredDataVisitNodes.Remove(instance);
            }
        }
    }

    /// <summary>
    /// Check if the specified type is an asset.
    /// </summary>
    /// <param name="assetType">Type of the asset.</param>
    /// <param name="throwException">A boolean indicating whether this method should throw an exception if the type is not an asset type.</param>
    /// <returns><c>true</c> if the asset is an asset type, false otherwise.</returns>
    public static bool IsAssetType(Type assetType, bool throwException = false)
    {
        ArgumentNullException.ThrowIfNull(assetType);

        if (!typeof(Asset).IsAssignableFrom(assetType))
        {
            if (throwException)
                throw new ArgumentException("Type [{0}] must be assignable to Asset or be a Package".ToFormat(assetType), nameof(assetType));
            return false;
        }
        return true;
    }

    /// <summary>
    /// Check if the specified type is an asset.
    /// </summary>
    /// <param name="assetType">Type of the asset.</param>
    /// <param name="throwException">A boolean indicating whether this method should throw an exception if the type is not an asset type.</param>
    /// <returns><c>true</c> if the asset is an asset type, false otherwise.</returns>
    public static bool IsAssetOrPackageType(Type assetType, bool throwException = false)
    {
        ArgumentNullException.ThrowIfNull(assetType);

        if (!typeof(Asset).IsAssignableFrom(assetType) && assetType != typeof(Package))
        {
            if (throwException)

View on GitHub (pinned to 96fad776d2)