{"record":{"id":"a6e9f06551671633","repo":"stride3d/stride","slug":"type-type-is-not-supported-as-a-modifiable-collection","errorCode":null,"errorMessage":"Type [{type}] is not supported as a modifiable collection","messagePattern":"Type \\[(.+?)\\] is not supported as a modifiable collection","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Reflection/TypeDescriptors/OldCollectionDescriptor.cs","lineNumber":115,"sourceCode":"\n                var removeAt = type.GetMethod(nameof(IList<object>.RemoveAt), [typeof(int)]);\n                if (removeAt != null)\n                    removeAtMethod = (obj, index) => removeAt.Invoke(obj, [index]);\n\n                var getItem = type.GetMethod(\"get_Item\", [typeof(int)]);\n                if (getItem != null)\n                    getIndexedItemMethod = (obj, index) => getItem.Invoke(obj, [index]);\n\n                var setItem = type.GetMethod(\"set_Item\", [typeof(int), ElementType]);\n                if (setItem != null)\n                    setIndexedItemMethod = (obj, index, value) => setItem.Invoke(obj, [index, value]);\n\n                HasIndexerAccessors = getItem != null && setItem != null;\n            }\n        }\n        else\n        {\n            throw new ArgumentException($\"Type [{type}] is not supported as a modifiable collection\");\n        }\n\n        HasAdd = addMethod != null;\n        HasRemove = removeMethod != null;\n        HasInsert = insertMethod != null;\n        HasRemoveAt = removeAtMethod != null;\n    }\n\n    public override void Initialize(IComparer<object> keyComparer)\n    {\n        base.Initialize(keyComparer);\n\n        IsPureCollection = Count == 0;\n    }\n\n    public override DescriptorCategory Category => DescriptorCategory.Collection;\n\n    /// <summary>","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Reflection/TypeDescriptors/OldCollectionDescriptor.cs#L97-L133","documentation":"OldCollectionDescriptor's constructor inspects the type for supported collection interfaces (IList/ICollection/arrays with indexers, etc.). If the type implements none of the supported modifiable collection shapes, it throws ArgumentException 'Type [{type}] is not supported as a modifiable collection'. The descriptor needs known Add/Remove/Insert/indexer methods to support editing.","triggerScenarios":"Constructing OldCollectionDescriptor for a type that is not a recognized modifiable collection — e.g. IEnumerable-only types, custom collections implementing neither IList nor ICollection<T>, dictionaries routed to the wrong descriptor.","commonSituations":"Trying to serialize/edit read-only sequences (yield-return iterators, LINQ query results); custom collection classes missing standard interfaces; types registered with the wrong descriptor factory branch.","solutions":["Make the type implement IList or ICollection<T> (e.g. inherit from List<T> or Collection<T>).","Use a supported collection type (List<T>, T[], ObservableCollection<T>, HashSet<T>) instead of a custom one.","Register the type with the correct descriptor (ObjectDescriptor or SetDescriptor) if it is not a collection."],"exampleFix":"// before\npublic class MyItems { /* no collection interface */ }\n// after\npublic class MyItems : List<Item> { }","handlingStrategy":"validation","validationCode":"bool supported = type.IsArray\n    || typeof(IList).IsAssignableFrom(type)\n    || (type.IsGenericType && typeof(ICollection<>).IsAssignableFrom(type.GetGenericTypeDefinition().MakeGenericType(type.GetGenericArguments())));\nif (!supported) throw new InvalidOperationException($\"{type} is not a supported modifiable collection\");","typeGuard":"static bool IsModifiableCollection(Type t) => t.IsArray || typeof(IList).IsAssignableFrom(t) || t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICollection<>));","tryCatchPattern":"try { var d = new OldCollectionDescriptor(factory, type, emit, conv); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"not supported as a modifiable collection\")) { /* fall back to ObjectDescriptor */ }","preventionTips":["Base serializable collections on List<T>, Collection<T>, arrays, or ObservableCollection<T>.","Ensure custom collections implement IList or ICollection<T>.","Avoid serializing IEnumerable-only results (LINQ queries, iterators)."],"tags":["reflection","collection","unsupported-type","csharp"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}