stride3d/stride · error · ArgumentException
The guid of the key does not match the guid of the value
Error message
The guid of the key does not match the guid of the value
What it means
AssetPartCollection.Add(KeyValuePair<Guid,TAssetPartDesign>) throws ArgumentException when the dictionary key does not equal part.Value.Part.Id. The collection (a SortedList keyed by Guid) enforces that the key always matches the id inside the design so lookups by part id stay consistent.
Solutions
- Use the key design.Part.Id when constructing the KeyValuePair.
- Call Add(TAssetPartDesign) directly and let the collection key on Part.Id itself.
- Call RefreshKeys() on the collection after changing ids of contained parts.
Example fix
// before collection.Add(new KeyValuePair<Guid, Design>(oldGuid, design)); // after collection.Add(new KeyValuePair<Guid, Design>(design.Part.Id, design));
Defensive patterns
Strategy: validation
Validate before calling
if (kvp.Key != kvp.Value?.Part.Id) throw new ArgumentException("Key must equal kvp.Value.Part.Id"); Try / catch
try { collection.Add(kvp); } catch (ArgumentException ex) when (ex.Message.Contains("guid of the key")) { collection.Add(kvp.Value.Part.Id, kvp.Value); } Prevention
- Prefer Add(TAssetPartDesign) which keys on Part.Id automatically.
- Call RefreshKeys() after mutating any part's Id.
- Never construct KeyValuePair entries by hand from stale ids.
When it happens
Trigger: Calling Add(new KeyValuePair<Guid,TAssetPartDesign>(someGuid, design)) where someGuid != design.Part.Id.
Common situations: Building the collection from serialized key/value pairs where the id of the part was changed after the key was computed (e.g. ids updated during a refresh but keys not refreshed).
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- A part Id cannot be empty.
- Value cannot be null. (Parameter 'part')
- Asset already exist in this collection
- Unable to decode asset part reference
- The given id cannot be found in the root parts of this…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/994c7eefc2ba620d.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/AssetPartCollection.cs:22
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)
{
Add(value.Part.Id, value);
}
}
}
public class AssetPartCollectionSerializer<TAssetPartDesign, TAssetPart> : DataSerializer<AssetPartCollection<TAssetPartDesign, TAssetPart>>, IDataSerializerGenericInstantiationView on GitHub (pinned to 96fad776d2)