stride3d/stride · error · ArgumentNullException
Value cannot be null. (Parameter 'part')
Error message
Value cannot be null. (Parameter 'part')
What it means
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.
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.
Example fix
// before collection.Add(partDesign); // partDesign may be null // after if (partDesign != null) collection.Add(partDesign);
Defensive patterns
Strategy: validation
Validate before calling
if (partDesign == null) return; // skip null part entries before Add
Type guard
bool IsValidPart<TDesign>(TDesign? d) where TDesign : class => d is not null;
Try / catch
try { collection.Add(partDesign); } catch (ArgumentNullException) { log.Warning("Skipped null part design"); } Prevention
- 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.
When it happens
Trigger: Calling assetPartCollection.Add(null), or Add(keyValuePair) where the KeyValuePair's Value is null (the Add(KeyValuePair<Guid,TAssetPartDesign>) path surfaces this as 'part').
Common situations: Populating an entity/prefab asset from data where a part entry failed to deserialize and is null; test code probing null handling (TestAddWithNullPartThrows).
Related errors
- The guid of the key does not match the guid of the value
- Cannot add an empty asset item reference
- Asset already exist in this collection
- Unable to find the base
- Unable to find the graph corresponding to the base part
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/408a8ef28dfdc27e.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/AssetPartCollection.cs:15
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using Stride.Core.Serialization;
namespace Stride.Core.Assets;
[DataSerializer(typeof(AssetPartCollectionSerializer<,>), Mode = DataSerializerGenericMode.GenericArguments)]
public sealed class AssetPartCollection<TAssetPartDesign, TAssetPart> : SortedList<Guid, TAssetPartDesign>
where TAssetPartDesign : IAssetPartDesign<TAssetPart>
where TAssetPart : IIdentifiable
{
public void Add(TAssetPartDesign part)
{
if (part == null) throw new ArgumentNullException(nameof(part));
Add(part.Part.Id, part);
}
public void Add(KeyValuePair<Guid, TAssetPartDesign> part)
{
if (part.Value == null) throw new ArgumentNullException(nameof(part));
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));
Add(part.Key, part.Value);
}
/// <summary>
/// Refreshes the keys of this collection. Must be called if some ids of the contained parts have changed.
/// </summary>
public void RefreshKeys()
{
var values = Values.ToList();
Clear();
foreach (var value in values)View on GitHub (pinned to 96fad776d2)