dotnet/maui · warning · NotSupportedException
Element IList<Element>.this[int index] { get => _inner[index
Error message
Element IList<Element>.this[int index] { get => _inner[index]; set => throw new NotSupportedException(); } What it means
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.
Source
Thrown at src/Controls/src/Core/Element/Element.cs:1195
else if (this is DatePicker dp && DateTime.TryParse(text, out DateTime dpResult))
{
dp.Date = dpResult;
return true;
}
return false;
}
class TemporaryWrapper : IList<Element>
{
IReadOnlyList<Element> _inner;
public TemporaryWrapper(IReadOnlyList<Element> inner)
{
_inner = inner;
}
Element IList<Element>.this[int index] { get => _inner[index]; set => throw new NotSupportedException(); }
int ICollection<Element>.Count => _inner.Count;
bool ICollection<Element>.IsReadOnly => true;
void ICollection<Element>.Add(Element item) => throw new NotSupportedException();
void ICollection<Element>.Clear() => throw new NotSupportedException();
bool ICollection<Element>.Contains(Element item) => _inner.IndexOf(item) != -1;
void ICollection<Element>.CopyTo(Element[] array, int arrayIndex) => throw new NotSupportedException();
IEnumerator<Element> IEnumerable<Element>.GetEnumerator() => _inner.GetEnumerator();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => _inner.GetEnumerator();
int IList<Element>.IndexOf(Element item) => _inner.IndexOf(item);View on GitHub (pinned to f377ff1c5e)
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.
Example fix
// before (via reflection on internal wrapper) inner[index] = newElement; // NotSupportedException // after element.InsertLogicalChild(index, newElement);
Defensive patterns
Strategy: validation
Validate before calling
// LogicalChildren is read-only; never set the indexer. Use InsertLogicalChild.
if (element.LogicalChildren.IsReadOnly)
return; // do not attempt writes Try / catch
// This is a read-only adapter reached only via reflection; callers should not cast to a writable IList.
Prevention
- Use InsertLogicalChild/RemoveLogicalChild instead of writing to LogicalChildren.
- Treat LogicalChildren as read-only.
- Avoid reflection into internal Element collections.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- void ICollection<Element>.Add(Element item) => throw new Not
- void ICollection<Element>.Clear() => throw new NotSupportedE
- void ICollection<Element>.CopyTo(Element[] array, int arrayI
- void IList<Element>.Insert(int index, Element item) => throw
- bool ICollection<Element>.Remove(Element item) => throw new
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/60f10e07eaf4eddd.
Report an issue: GitHub.