stride3d/stride · error · InvalidOperationException
GetObject can only be used for Permutation or Object keys
Error message
GetObject can only be used for Permutation or Object keys
What it means
GetObject, like SetObject, is restricted to Permutation or Object keys because object lookups read from the ObjectValues reference array. Typed keys store data elsewhere, so requesting them via GetObject throws InvalidOperationException.
Solutions
- Filter keys by Type == ParameterKeyType.Permutation || Type == ParameterKeyType.Object before calling GetObject
- Use typed Get<T> for typed keys
- Note GetObject returns null (rather than throwing) when the key is valid but unset — only the key-type mismatch throws
Example fix
// before
var v = collection.GetObject(someFloatKey);
// after
var v = someFloatKey.Type == ParameterKeyType.Permutation || someFloatKey.Type == ParameterKeyType.Object
? collection.GetObject(someFloatKey)
: collection.Get(someFloatKey); Defensive patterns
Strategy: validation
Validate before calling
object v = key.Type is ParameterKeyType.Permutation or ParameterKeyType.Object
? collection.GetObject(key)
: null; Type guard
bool CanGetObject(ParameterKey key) => key.Type is ParameterKeyType.Permutation or ParameterKeyType.Object;
Try / catch
try { v = collection.GetObject(key); } catch (InvalidOperationException) { v = null; /* handle typed keys via Get<T> */ } Prevention
- When enumerating all keys, filter by key.Type before GetObject
- Remember GetObject legitimately returns null for valid-but-unset keys — only the type check throws
When it happens
Trigger: Calling GetObject with a key whose Type is not Permutation or Object.
Common situations: Debug/dump code enumerating keys and calling GetObject on every one; reflection-based serialization of parameter collections.
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
- SetObject can only be used for Permutation or Object keys
- Could not find underlying CPU buffer data and no command…
- Can only merge simple MeshDrawData.
- Cannot query package with dependencies when it is not…
- [ . ] must be in
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/0f16d6d83bdde8ea.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Foundation/Rendering/ParameterCollection.cs:513
{
if (key.Type != ParameterKeyType.Permutation && key.Type != ParameterKeyType.Object)
throw new InvalidOperationException("SetObject can only be used for Permutation or Object keys");
var accessor = GetObjectParameterHelper(key);
if (key.Type == ParameterKeyType.Permutation)
{
var oldValue = ObjectValues[accessor.Offset];
if ((oldValue != null && (value == null || !oldValue.Equals(value))) // oldValue non null => check equality
|| (oldValue == null && value != null)) // oldValue null => check if value too
PermutationCounter++;
}
ObjectValues[accessor.Offset] = value;
}
public object GetObject(ParameterKey key)
{
if (key.Type != ParameterKeyType.Permutation && key.Type != ParameterKeyType.Object)
throw new InvalidOperationException("GetObject can only be used for Permutation or Object keys");
var accessor = GetObjectParameterHelper(key, false);
if (accessor.Offset == -1)
return null;
return ObjectValues[accessor.Offset];
}
public bool Remove(ParameterKey key)
{
for (int i = 0; i < parameterKeyInfos.Count; ++i)
{
if (parameterKeyInfos[i].Key == key)
{
parameterKeyInfos.SwapRemoveAt(i);
LayoutCounter++;
return true;
}View on GitHub (pinned to 96fad776d2)