{"record":{"id":"0f16d6d83bdde8ea","repo":"stride3d/stride","slug":"getobject-can-only-be-used-for-permutation-or-object-keys","errorCode":null,"errorMessage":"GetObject can only be used for Permutation or Object keys","messagePattern":"GetObject can only be used for Permutation or Object keys","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Foundation/Rendering/ParameterCollection.cs","lineNumber":513,"sourceCode":"        {\n            if (key.Type != ParameterKeyType.Permutation && key.Type != ParameterKeyType.Object)\n                throw new InvalidOperationException(\"SetObject can only be used for Permutation or Object keys\");\n\n            var accessor = GetObjectParameterHelper(key);\n            if (key.Type == ParameterKeyType.Permutation)\n            {\n                var oldValue = ObjectValues[accessor.Offset];\n                if ((oldValue != null && (value == null || !oldValue.Equals(value))) // oldValue non null => check equality\n                    || (oldValue == null && value != null)) // oldValue null => check if value too\n                        PermutationCounter++;\n            }\n            ObjectValues[accessor.Offset] = value;\n        }\n\n        public object GetObject(ParameterKey key)\n        {\n            if (key.Type != ParameterKeyType.Permutation && key.Type != ParameterKeyType.Object)\n                throw new InvalidOperationException(\"GetObject can only be used for Permutation or Object keys\");\n\n            var accessor = GetObjectParameterHelper(key, false);\n            if (accessor.Offset == -1)\n                return null;\n\n            return ObjectValues[accessor.Offset];\n        }\n\n        public bool Remove(ParameterKey key)\n        {\n            for (int i = 0; i < parameterKeyInfos.Count; ++i)\n            {\n                if (parameterKeyInfos[i].Key == key)\n                {\n                    parameterKeyInfos.SwapRemoveAt(i);\n                    LayoutCounter++;\n                    return true;\n                }","sourceCodeStart":495,"sourceCodeEnd":531,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Rendering/ParameterCollection.cs#L495-L531","documentation":"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.","triggerScenarios":"Calling GetObject with a key whose Type is not Permutation or Object.","commonSituations":"Debug/dump code enumerating keys and calling GetObject on every one; reflection-based serialization of parameter collections.","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"],"exampleFix":"// before\nvar v = collection.GetObject(someFloatKey);\n// after\nvar v = someFloatKey.Type == ParameterKeyType.Permutation || someFloatKey.Type == ParameterKeyType.Object\n    ? collection.GetObject(someFloatKey)\n    : collection.Get(someFloatKey);","handlingStrategy":"validation","validationCode":"object v = key.Type is ParameterKeyType.Permutation or ParameterKeyType.Object\n    ? collection.GetObject(key)\n    : null;","typeGuard":"bool CanGetObject(ParameterKey key) => key.Type is ParameterKeyType.Permutation or ParameterKeyType.Object;","tryCatchPattern":"try { v = collection.GetObject(key); } catch (InvalidOperationException) { v = null; /* handle typed keys via Get<T> */ }","preventionTips":["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"],"tags":["rendering","parameters","invalid-operation"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}