{"record":{"id":"aa954dabb1399749","repo":"dotnet/maui","slug":"void-ilist-element-insert-int-index-element-item","errorCode":null,"errorMessage":"void IList<Element>.Insert(int index, Element item) => throw new NotSupportedException();","messagePattern":"void IList<Element>\\.Insert\\(int index, Element item\\) => throw new NotSupportedException\\(\\);","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"src/Controls/src/Core/Element/Element.cs","lineNumber":1215,"sourceCode":"\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);\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":1197,"sourceCodeEnd":1223,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Element/Element.cs#L1197-L1223","documentation":"Thrown by TemporaryWrapper.Insert(int, Element). TemporaryWrapper is the read-only IList<Element> adapter behind the obsolete Element.LogicalChildren property. All mutation methods throw NotSupportedException because the inner list is IReadOnlyList and IsReadOnly is true.","triggerScenarios":"Obtaining the internal TemporaryWrapper (via reflection or inside Hot Reload internals) and calling Insert. The public ReadOnlyCollection guards this; reaching Insert requires direct access to the adapter.","commonSituations":"Reflection-based or designer tooling attempting to insert into the logical-children backing collection; assuming the wrapper supports insertion.","solutions":["Use InsertLogicalChild(index, element) to add children at a position.","Treat LogicalChildren as read-only.","Do not write to internal Element collections."],"exampleFix":"// before (reflection on internal wrapper)\nwrapper.Insert(0, child); // NotSupportedException\n// after\nelement.InsertLogicalChild(0, child);","handlingStrategy":"validation","validationCode":"if (element.LogicalChildren.IsReadOnly)\n    return; // use InsertLogicalChild instead","typeGuard":null,"tryCatchPattern":"// Adapter reached only via reflection; use InsertLogicalChild instead.","preventionTips":["Insert children via InsertLogicalChild(index, child).","Treat LogicalChildren as read-only.","Do not reflect into internal Element collections."],"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"}