{"record":{"id":"5757e3ad118d1878","repo":"stride3d/stride","slug":"invalid-type-0-type-must-be-assignable-to-asset","errorCode":null,"errorMessage":"Invalid type [{0}]. Type must be assignable to Asset","messagePattern":"Invalid type \\[(.+?)\\]\\. Type must be assignable to Asset","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/AssetImporterParameters.cs","lineNumber":48,"sourceCode":"    /// <param name=\"supportedTypes\">The supported types.</param>\n    public AssetImporterParameters(params Type[] supportedTypes) : this((IEnumerable<Type>)supportedTypes)\n    {\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"AssetImporterParameters\"/> class.\n    /// </summary>\n    /// <param name=\"supportedTypes\">The supported types.</param>\n    /// <exception cref=\"System.ArgumentNullException\">supportedTypes</exception>\n    /// <exception cref=\"System.ArgumentException\">Invalid type [{0}]. Type must be assignable to Asset.ToFormat(type);supportedTypes</exception>\n    public AssetImporterParameters(IEnumerable<Type> supportedTypes) : this()\n    {\n        ArgumentNullException.ThrowIfNull(supportedTypes);\n        foreach (var type in supportedTypes)\n        {\n            if (!typeof(Asset).IsAssignableFrom(type))\n            {\n                throw new ArgumentException(\"Invalid type [{0}]. Type must be assignable to Asset\".ToFormat(type), nameof(supportedTypes));\n            }\n            SelectedOutputTypes[type] = true;\n        }\n    }\n\n    /// <summary>\n    /// Gets the import input parameters.\n    /// </summary>\n    /// <value>The import input parameters.</value>\n    public PropertyCollection InputParameters { get; private set; }\n\n    /// <summary>\n    /// Gets the selected output types.\n    /// </summary>\n    /// <value>The selected output types.</value>\n    public Dictionary<Type, bool> SelectedOutputTypes { get; private set; }\n\n    /// <summary>","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/AssetImporterParameters.cs#L30-L66","documentation":"The AssetImporterParameters constructor that takes a set of supported types validates each type is assignable to Asset; passing any non-asset type (or an interface/abstract-only set) throws ArgumentException naming 'supportedTypes'. It guards the importer's output-type selection map.","triggerScenarios":"Constructing AssetImporterParameters with a supportedTypes collection containing e.g. typeof(object), a custom non-Asset class, a struct, or null entries.","commonSituations":"Typo'd generic argument when wiring an importer; using a ViewModel/DTO type instead of the asset type; reflection-based code picking the wrong type from an assembly.","solutions":["Ensure every element of supportedTypes is a class deriving from Stride.Core.Assets.Asset","Fix the type passed at the construction site (check generic/reflection code)","Add a pre-check with typeof(Asset).IsAssignableFrom(t) before constructing","Remove placeholder/abstract types that are not concrete asset outputs"],"exampleFix":"// before\nnew AssetImporterParameters(new[] { typeof(object) });\n// after\nnew AssetImporterParameters(new[] { typeof(TextureAsset) }); // derives from Asset","handlingStrategy":"validation","validationCode":"foreach (var t in supportedTypes)\n    if (t == null || !typeof(Asset).IsAssignableFrom(t))\n        throw new ArgumentException($\"{t} is not an Asset\");","typeGuard":"static bool IsAssetType(Type t) => t != null && typeof(Asset).IsAssignableFrom(t);","tryCatchPattern":"try { var p = new AssetImporterParameters(supportedTypes); }\ncatch (ArgumentException ex) when (ex.ParamName == \"supportedTypes\")\n{ log.Error($\"Invalid importer type: {ex.Message}\"); }","preventionTips":["Use typeof(SomeConcreteAsset) literals where possible","Filter reflection-derived types with IsAssignableFrom before passing","Write a unit test that constructs importers with their declared types"],"tags":["assets","type-check","invalid-argument"],"backgroundTag":"type-mismatch","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}