{"record":{"id":"cde57878734ec646","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-asset","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'asset')","messagePattern":"Value cannot be null\\. \\(Parameter 'asset'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/AssetItem.cs","lineNumber":48,"sourceCode":"    /// <param name=\"asset\">The asset.</param>\n    /// <exception cref=\"ArgumentNullException\">location</exception>\n    /// <exception cref=\"ArgumentNullException\">asset</exception>\n    public AssetItem(UFile location, Asset asset) : this(location, asset, null)\n    {\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"AssetItem\" /> class.\n    /// </summary>\n    /// <param name=\"location\">The location.</param>\n    /// <param name=\"asset\">The asset.</param>\n    /// <param name=\"package\">The package.</param>\n    /// <exception cref=\"ArgumentNullException\">location</exception>\n    /// <exception cref=\"ArgumentNullException\">asset</exception>\n    internal AssetItem(UFile location, Asset asset, Package? package)\n    {\n        this.location = location ?? throw new ArgumentNullException(nameof(location));\n        this.asset = asset ?? throw new ArgumentNullException(nameof(asset));\n        Package = package;\n        isDirty = true;\n    }\n\n    /// <summary>\n    /// Gets the qualified URL of this asset (rooted under its package's namespace, e.g. /MyGame/Ground).\n    /// </summary>\n    /// <value>The location.</value>\n    [DataMember]\n    public UFile Location { get => location; internal set => location = value ?? throw new ArgumentNullException(nameof(value)); }\n\n    /// <summary>\n    /// The asset's unqualified URL: its <see cref=\"Location\"/> without the package namespace root\n    /// (equal to <see cref=\"Location\"/> for a bare package).\n    /// </summary>\n    public UFile UnqualifiedUrl => new(AssetNamespaceHelper.Unqualify(Location.FullPath, Package?.Container?.AssetNamespace ?? Package?.AssetNamespace));\n\n    /// <summary>","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/AssetItem.cs#L30-L66","documentation":"The AssetItem constructor validates its arguments before building the item: it throws ArgumentNullException when the asset parameter is null. It is a guard clause on the constructor input, so a caller passed a null Asset reference (the UFile location may be perfectly valid, but an AssetItem cannot wrap a missing asset).","triggerScenarios":"Creating an AssetItem when the Asset variable is null — typically a failed asset load (returned null) passed straight into AssetItem, or a placeholder created before the asset is deserialized.","commonSituations":"Load pipeline that swallows deserialization errors and continues with null; constructing package items in bulk from a list containing nulls; refactored lazy-loading code where the asset is not yet materialized.","solutions":["Ensure the Asset is successfully loaded/constructed before wrapping it in an AssetItem","Fix the upstream load failure that returned null instead of throwing","Skip or log entries with null assets before creating AssetItems","Construct the concrete asset instance yourself when building assets programmatically"],"exampleFix":"// before\nvar asset = LoadAssetOrNull(path);\nvar item = new AssetItem(url, asset); // throws when null\n// after\nvar asset = LoadAssetOrNull(path) ?? throw new InvalidOperationException($\"Failed to load {path}\");\nvar item = new AssetItem(url, asset);","handlingStrategy":"validation","validationCode":"if (asset == null)\n    throw new InvalidOperationException($\"Asset failed to load for {url}\");\nvar item = new AssetItem(url, asset, package);","typeGuard":"static bool CanWrap(Asset a) => a != null;","tryCatchPattern":"try { item = new AssetItem(url, asset, package); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"asset\")\n{ log.Error($\"Asset for {url} was null\"); }","preventionTips":["Do not swallow load errors; propagate them instead of returning null","Filter nulls from bulk asset lists before creating items","Use non-null asset construction for programmatically created assets"],"tags":["assets","null-argument","asset-item"],"backgroundTag":"null-argument","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"}