{"record":{"id":"60f10e07eaf4eddd","repo":"dotnet/maui","slug":"element-ilist-element-this-int-index-get-i","errorCode":null,"errorMessage":"Element IList<Element>.this[int index] { get => _inner[index]; set => throw new NotSupportedException(); }","messagePattern":"Element IList<Element>\\.this\\[int index\\] (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"src/Controls/src/Core/Element/Element.cs","lineNumber":1195,"sourceCode":"\t\t\telse if (this is DatePicker dp && DateTime.TryParse(text, out DateTime dpResult))\n\t\t\t{\n\t\t\t\tdp.Date = dpResult;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t}\n\n\t\tclass TemporaryWrapper : IList<Element>\n\t\t{\n\t\t\tIReadOnlyList<Element> _inner;\n\n\t\t\tpublic TemporaryWrapper(IReadOnlyList<Element> inner)\n\t\t\t{\n\t\t\t\t_inner = inner;\n\t\t\t}\n\n\t\t\tElement IList<Element>.this[int index] { get => _inner[index]; set => throw new NotSupportedException(); }\n\n\t\t\tint ICollection<Element>.Count => _inner.Count;\n\n\t\t\tbool ICollection<Element>.IsReadOnly => true;\n\n\t\t\tvoid ICollection<Element>.Add(Element item) => throw new NotSupportedException();\n\n\t\t\tvoid ICollection<Element>.Clear() => throw new NotSupportedException();\n\n\t\t\tbool ICollection<Element>.Contains(Element item) => _inner.IndexOf(item) != -1;\n\n\t\t\tvoid ICollection<Element>.CopyTo(Element[] array, int arrayIndex) => throw new NotSupportedException();\n\n\t\t\tIEnumerator<Element> IEnumerable<Element>.GetEnumerator() => _inner.GetEnumerator();\n\n\t\t\tSystem.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => _inner.GetEnumerator();\n\n\t\t\tint IList<Element>.IndexOf(Element item) => _inner.IndexOf(item);","sourceCodeStart":1177,"sourceCodeEnd":1213,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Element/Element.cs#L1177-L1213","documentation":"Thrown by the indexer setter of TemporaryWrapper, a private read-only IList<Element> adapter wrapping an IReadOnlyList<Element>. TemporaryWrapper is used by the obsolete Element.LogicalChildren property (for Hot Reload) to expose logical children as a ReadOnlyCollection. The setter throws NotSupportedException because the underlying list is read-only and the wrapper marks IsReadOnly = true.","triggerScenarios":"Casting the obsolete LogicalChildren ReadOnlyCollection's inner list and calling the indexer setter: element.LogicalChildren (via reflection or framework internals)[index] = newElement. The public ReadOnlyCollection already blocks this, so this only fires through reflection/internal access to the wrapper.","commonSituations":"Reflection-based tooling, serializers, or Hot Reload infrastructure attempting to write through the indexer of the LogicalChildren backing wrapper; incorrectly assuming the returned collection is mutable.","solutions":["Use the public API: InsertLogicalChild / RemoveLogicalChild to modify logical children.","If consuming LogicalChildren, treat it as read-only (it is wrapped in ReadOnlyCollection by the public property).","Avoid reflecting into the internal TemporaryWrapper; it is explicitly a read-only adapter."],"exampleFix":"// before (via reflection on internal wrapper)\ninner[index] = newElement; // NotSupportedException\n// after\nelement.InsertLogicalChild(index, newElement);","handlingStrategy":"validation","validationCode":"// LogicalChildren is read-only; never set the indexer. Use InsertLogicalChild.\nif (element.LogicalChildren.IsReadOnly)\n    return; // do not attempt writes","typeGuard":null,"tryCatchPattern":"// This is a read-only adapter reached only via reflection; callers should not cast to a writable IList.","preventionTips":["Use InsertLogicalChild/RemoveLogicalChild instead of writing to LogicalChildren.","Treat LogicalChildren as read-only.","Avoid reflection into internal Element collections."],"tags":["maui","readonly-collection","logicalchildren","notsupported","hot-reload"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}