{"record":{"id":"25f1fd2b52e0a57f","repo":"dotnet/maui","slug":"void-ilist-element-removeat-int-index-throw-n","errorCode":null,"errorMessage":"void IList<Element>.RemoveAt(int index) => throw new NotSupportedException();","messagePattern":"void IList<Element>\\.RemoveAt\\(int index\\) => throw new NotSupportedException\\(\\);","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"src/Controls/src/Core/Element/Element.cs","lineNumber":1219,"sourceCode":"\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);\n\n\t\t\tvoid IList<Element>.Insert(int index, Element item) => throw new NotSupportedException();\n\n\t\t\tbool ICollection<Element>.Remove(Element item) => throw new NotSupportedException();\n\n\t\t\tvoid IList<Element>.RemoveAt(int index) => throw new NotSupportedException();\n\t\t}\n\t}\n}\n","sourceCodeStart":1201,"sourceCodeEnd":1223,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Element/Element.cs#L1201-L1223","documentation":"Thrown by TemporaryWrapper.RemoveAt(int). TemporaryWrapper is the read-only IList<Element> adapter backing the obsolete Element.LogicalChildren ReadOnlyCollection. At the IList contract level removal-by-index is unsupported because the inner IReadOnlyList cannot be mutated and IsReadOnly is true.","triggerScenarios":"Obtaining the internal TemporaryWrapper (reflection/internal access) and calling RemoveAt. The public ReadOnlyCollection blocks this; the adapter must be accessed directly for the throw to fire.","commonSituations":"Reflection-based tooling or Hot Reload internals attempting to remove a child by index from the backing collection; assuming the wrapper is mutable.","solutions":["Use RemoveLogicalChild to remove children, or remove then re-insert to reposition.","Treat LogicalChildren as read-only.","Do not manipulate internal Element collections via reflection."],"exampleFix":"// before (reflection on internal wrapper)\nwrapper.RemoveAt(0); // NotSupportedException\n// after\nelement.RemoveLogicalChild(element.LogicalChildren[0]);","handlingStrategy":"validation","validationCode":"if (element.LogicalChildren.IsReadOnly)\n    return; // use RemoveLogicalChild instead","typeGuard":null,"tryCatchPattern":"// Adapter reached only via reflection; remove via RemoveLogicalChild instead.","preventionTips":["Remove children via RemoveLogicalChild rather than RemoveAt on the backing list.","Treat LogicalChildren as read-only.","Do not manipulate internal Element collections via reflection."],"tags":["maui","readonly-collection","logicalchildren","notsupported"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}