{"record":{"id":"ea561ae79a22b247","repo":"stride3d/stride","slug":"setdescriptor-should-not-call-function-getvalue-with-int","errorCode":null,"errorMessage":"SetDescriptor should not call function 'GetValue' with int index parameter.","messagePattern":"SetDescriptor should not call function 'GetValue' with int index parameter\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Reflection/TypeDescriptors/SetDescriptor.cs","lineNumber":160,"sourceCode":"    /// <summary>\n    /// Get set value by index\n    /// </summary>\n    /// <param name=\"set\">The set.</param>\n    /// <param name=\"index\">Index of value.</param>\n    /// <returns></returns>\n    public override object? GetValue(object set, object index)\n    {\n        return Contains(set, index) ? index : null;\n    }\n\n    /// <summary>\n    /// Returns the value matching the given index in the set.\n    /// </summary>\n    /// <param name=\"set\">The set.</param>\n    /// <param name=\"index\">The index.</param>\n    public override object GetValue(object set, int index)\n    {\n        throw new InvalidOperationException(\"SetDescriptor should not call function 'GetValue' with int index parameter.\");\n    }\n\n    /// <summary>\n    /// Set the set value by index\n    /// </summary>\n    /// <param name=\"set\">The set.</param>\n    /// <param name=\"index\">Index of value.</param>\n    /// <returns></returns>\n    public override void SetValue(object set, object index, object? value)\n    {\n        ArgumentNullException.ThrowIfNull(set);\n\n        if (Contains(set, index))\n        {\n            Remove(set, index);\n        }\n        if (!Contains(set, value))\n        {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Reflection/TypeDescriptors/SetDescriptor.cs#L142-L178","documentation":"Sets are unordered, so GetValue(set, int index) has no meaningful implementation in SetDescriptor. The method throws unconditionally as an API-contract guard: element access on a set must use the overload that takes the item/key, not an index.","triggerScenarios":"Calling SetDescriptor.GetValue(set, i) directly, or generic code that enumerates descriptor indices (e.g. for i in 0..Count) and calls GetValue(set, i).","commonSituations":"Inspectors/debuggers rendering collections positionally; code shared with ListDescriptor that reads elements by index.","solutions":["Enumerate the set directly (foreach / IEnumerable) instead of indexed access","Use the GetValue overload that accepts the item/key reference","Special-case SetDescriptor in generic collection-rendering code"],"exampleFix":"// before\nvar item = descriptor.GetValue(mySet, i);\n// after\nforeach (var item in (IEnumerable)mySet) { ... }","handlingStrategy":"validation","validationCode":"object GetItem(object set, object descriptor, int index)\n{\n    if (descriptor is SetDescriptor)\n        return ((IEnumerable)set).Cast<object>().ElementAtOrDefault(index);\n    return ((CollectionDescriptor)descriptor).GetValue(set, index);\n}","typeGuard":"bool IsSetDescriptor(object d) => d is SetDescriptor;","tryCatchPattern":"try { item = descriptor.GetValue(set, i); }\ncatch (InvalidOperationException) { item = ((IEnumerable)set).Cast<object>().Skip(i).FirstOrDefault(); }","preventionTips":["Enumerate sets with foreach instead of indices","Guard generic collection readers by descriptor kind","Do not assume Count/index semantics apply to sets"],"tags":["reflection","unsupported-operation","sets"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}