{"record":{"id":"408a8ef28dfdc27e","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-part","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'part')","messagePattern":"Value cannot be null\\. \\(Parameter 'part'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/AssetPartCollection.cs","lineNumber":15,"sourceCode":"﻿// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)\n// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.\n\nusing Stride.Core.Serialization;\n\nnamespace Stride.Core.Assets;\n\n[DataSerializer(typeof(AssetPartCollectionSerializer<,>), Mode = DataSerializerGenericMode.GenericArguments)]\npublic sealed class AssetPartCollection<TAssetPartDesign, TAssetPart> : SortedList<Guid, TAssetPartDesign>\n    where TAssetPartDesign : IAssetPartDesign<TAssetPart>\n    where TAssetPart : IIdentifiable\n{\n    public void Add(TAssetPartDesign part)\n    {\n        if (part == null) throw new ArgumentNullException(nameof(part));\n        Add(part.Part.Id, part);\n    }\n\n    public void Add(KeyValuePair<Guid, TAssetPartDesign> part)\n    {\n        if (part.Value == null) throw new ArgumentNullException(nameof(part));\n        if (part.Key != part.Value.Part.Id) throw new ArgumentException(@\"The guid of the key does not match the guid of the value\", nameof(part));\n        Add(part.Key, part.Value);\n    }\n\n    /// <summary>\n    /// Refreshes the keys of this collection. Must be called if some ids of the contained parts have changed.\n    /// </summary>\n    public void RefreshKeys()\n    {\n        var values = Values.ToList();\n        Clear();\n        foreach (var value in values)","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/AssetPartCollection.cs#L1-L33","documentation":"AssetPartCollection<TAssetPartDesign,TAssetPart>.Add(TAssetPartDesign) throws ArgumentNullException when the part design being added is null. The collection requires a non-null design carrying both a Part.Id and the part itself.","triggerScenarios":"Calling assetPartCollection.Add(null), or Add(keyValuePair) where the KeyValuePair's Value is null (the Add(KeyValuePair<Guid,TAssetPartDesign>) path surfaces this as 'part').","commonSituations":"Populating an entity/prefab asset from data where a part entry failed to deserialize and is null; test code probing null handling (TestAddWithNullPartThrows).","solutions":["Ensure the TAssetPartDesign instance is constructed before calling Add.","Check the data source producing null parts and skip or repair those entries.","Add a null check at the call site before invoking Add."],"exampleFix":"// before\ncollection.Add(partDesign); // partDesign may be null\n// after\nif (partDesign != null) collection.Add(partDesign);","handlingStrategy":"validation","validationCode":"if (partDesign == null) return; // skip null part entries before Add","typeGuard":"bool IsValidPart<TDesign>(TDesign? d) where TDesign : class => d is not null;","tryCatchPattern":"try { collection.Add(partDesign); } catch (ArgumentNullException) { log.Warning(\"Skipped null part design\"); }","preventionTips":["Null-check deserialized part designs before adding them.","Fail fast in deserialization code when a design entry is null.","Use nullable-reference-types warnings to catch null flows."],"tags":["assets","null","collection"],"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"}