{"record":{"id":"bcfeb33f72285250","repo":"dotnet/maui","slug":"bool-icollection-element-remove-element-item","errorCode":null,"errorMessage":"bool ICollection<Element>.Remove(Element item) => throw new NotSupportedException();","messagePattern":"bool ICollection<Element>\\.Remove\\(Element item\\) => throw new NotSupportedException\\(\\);","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"src/Controls/src/Core/Element/Element.cs","lineNumber":1217,"sourceCode":"\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":1199,"sourceCodeEnd":1223,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Element/Element.cs#L1199-L1223","documentation":"Thrown by TemporaryWrapper.Remove(Element). TemporaryWrapper is the read-only IList<Element> adapter behind the obsolete Element.LogicalChildren ReadOnlyCollection. Remove returns bool in the interface contract but the adapter throws NotSupportedException because the inner IReadOnlyList is not mutable.","triggerScenarios":"Obtaining the internal TemporaryWrapper (via reflection/internal access) and calling Remove. The public ReadOnlyCollection would block this first; reaching the adapter directly is required to hit this throw.","commonSituations":"Reflection-based tooling or designer code attempting to remove children through the backing collection; assuming the wrapper supports removal.","solutions":["Use RemoveLogicalChild(child) to remove logical children.","Treat LogicalChildren as read-only.","Avoid reflecting into internal Element collections."],"exampleFix":"// before (reflection on internal wrapper)\nwrapper.Remove(child); // NotSupportedException\n// after\nelement.RemoveLogicalChild(child);","handlingStrategy":"validation","validationCode":"if (element.LogicalChildren.IsReadOnly)\n    return; // use RemoveLogicalChild instead","typeGuard":null,"tryCatchPattern":"// Adapter reached only via reflection; use RemoveLogicalChild instead.","preventionTips":["Remove children via RemoveLogicalChild(child).","Treat LogicalChildren as read-only.","Do not manipulate internal 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"}