{"record":{"id":"b21a23186d1f871a","repo":"stride3d/stride","slug":"type-0-must-be-assignable-to-asset-or-be-a-package","errorCode":null,"errorMessage":"Type [{0}] must be assignable to Asset or be a Package","messagePattern":"Type \\[(.+?)\\] must be assignable to Asset or be a Package","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/AssetRegistry.cs","lineNumber":859,"sourceCode":"                RegisteredDataVisitNodes.Remove(instance);\n            }\n        }\n    }\n\n    /// <summary>\n    /// Check if the specified type is an asset.\n    /// </summary>\n    /// <param name=\"assetType\">Type of the asset.</param>\n    /// <param name=\"throwException\">A boolean indicating whether this method should throw an exception if the type is not an asset type.</param>\n    /// <returns><c>true</c> if the asset is an asset type, false otherwise.</returns>\n    public static bool IsAssetType(Type assetType, bool throwException = false)\n    {\n        ArgumentNullException.ThrowIfNull(assetType);\n\n        if (!typeof(Asset).IsAssignableFrom(assetType))\n        {\n            if (throwException)\n                throw new ArgumentException(\"Type [{0}] must be assignable to Asset or be a Package\".ToFormat(assetType), nameof(assetType));\n            return false;\n        }\n        return true;\n    }\n\n    /// <summary>\n    /// Check if the specified type is an asset.\n    /// </summary>\n    /// <param name=\"assetType\">Type of the asset.</param>\n    /// <param name=\"throwException\">A boolean indicating whether this method should throw an exception if the type is not an asset type.</param>\n    /// <returns><c>true</c> if the asset is an asset type, false otherwise.</returns>\n    public static bool IsAssetOrPackageType(Type assetType, bool throwException = false)\n    {\n        ArgumentNullException.ThrowIfNull(assetType);\n\n        if (!typeof(Asset).IsAssignableFrom(assetType) && assetType != typeof(Package))\n        {\n            if (throwException)","sourceCodeStart":841,"sourceCodeEnd":877,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/AssetRegistry.cs#L841-L877","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Make the registered type derive from Stride.Core.Assets.Asset.","Use the overload that accepts Package types if you intend to register a Package.","Pass throwException:false if you only want a boolean validity check instead of an exception."],"exampleFix":"// before\npublic class MyThing { } // not an Asset\nAssetRegistry.CheckAssetType(typeof(MyThing), true);\n// after\npublic class MyThing : Asset { }","handlingStrategy":"validation","validationCode":"if (!typeof(Asset).IsAssignableFrom(assetType)) throw new ArgumentException($\"{assetType} must derive from Asset\");","typeGuard":"bool IsAssetType(Type t) => typeof(Asset).IsAssignableFrom(t);","tryCatchPattern":"try { AssetRegistry.CheckAssetType(assetType, true); } catch (ArgumentException ex) when (ex.Message.Contains(\"assignable to Asset\")) { log.Error($\"{assetType} is not an Asset type\"); }","preventionTips":["Constrain generics with where T : Asset.","Verify base classes after refactors that move types in the hierarchy.","Use compile-time typeof checks instead of reflection strings."],"tags":["assets","type-mismatch","validation"],"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"}