{"record":{"id":"b3240a5d84b9e25b","repo":"tui-cs/Terminal.Gui","slug":"cloning-of-collection-type-type-name-is-not-supp","errorCode":null,"errorMessage":"Cloning of collection type {type.Name} is not supported unless it implements IList.","messagePattern":"Cloning of collection type (.+?) is not supported unless it implements IList\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/DeepCloner.cs","lineNumber":225,"sourceCode":"    [UnconditionalSuppressMessage (\"Trimming\", \"IL2072\", Justification = \"Collection cloning only instantiates the runtime collection type after filtering to supported IList implementations.\")]\n    private static object CloneCollection (object source, ConcurrentDictionary<object, object> visited)\n    {\n        Type type = source.GetType ();\n\n        // Check for immutable collections and throw if found\n        if (type.IsGenericType)\n        {\n            Type genericTypeDef = type.GetGenericTypeDefinition ();\n\n            if (genericTypeDef.FullName != null && genericTypeDef.FullName.StartsWith (\"System.Collections.Immutable\"))\n            {\n                throw new NotSupportedException ($\"Cloning of immutable collections like {type.Name} is not supported.\");\n            }\n        }\n\n        if (source is not IList)\n        {\n            throw new NotSupportedException ($\"Cloning of collection type {type.Name} is not supported unless it implements IList.\");\n        }\n\n        if (Activator.CreateInstance (type) is not IList tempList)\n        {\n            throw new NotSupportedException ($\"Cloning of collection type {type.Name} is not supported without a parameterless constructor.\");\n        }\n\n        // Add to visited before cloning contents to prevent circular reference issues\n        visited.TryAdd (source, tempList);\n\n        foreach (object? item in (IEnumerable)source)\n        {\n            object? clonedItem = DeepCloneInternal (item, visited);\n            tempList.Add (clonedItem);\n        }\n\n        return tempList;\n    }","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/DeepCloner.cs#L207-L243","documentation":"Thrown by DeepCloner.CloneCollection when the source collection implements IEnumerable but NOT IList, and is not an immutable collection (else error 38 fires). DeepCloner's collection-cloning strategy relies on IList.Add to populate the clone, so read-only or set/dictionary-style collections that lack IList are rejected.","triggerScenarios":"A [ConfigurationProperty] value is a collection type that does not implement IList — e.g. HashSet<T>, SortedSet<T>, a custom IEnumerable, or an IReadOnlyCollection.","commonSituations":"Using a HashSet/Set as a config value; a readonly collection wrapper; a custom collection that implements only IEnumerable.","solutions":["Use a collection type that implements IList (List<T>, or for dictionaries go through CloneDictionary which handles Dictionary<,>/ConcurrentDictionary<,>).","If a set is semantically required, store it as a List<T> config property and expose set semantics via a wrapper.","Avoid custom collection types as config property values; DeepCloner supports a closed set of shapes."],"exampleFix":"// before\n[ConfigurationProperty] public static HashSet<string>? Tags { get; set; }\n// after\n[ConfigurationProperty] public static List<string>? Tags { get; set; }","handlingStrategy":"validation","validationCode":"Type t = source.GetType ();\nif (source is not IList && t.GetGenericTypeDefinition ().FullName?.StartsWith (\"System.Collections.Immutable\") != true)\n    throw new NotSupportedException ($\"{t.Name} does not implement IList; DeepCloner cannot clone it.\");","typeGuard":"static bool IsClonableCollection (object o)\n{\n    Type t = o.GetType ();\n    if (o is IList) return true;\n    if (o is IDictionary) return true;\n    return false;\n}","tryCatchPattern":"try { ConfigurationManager.Apply (); }\ncatch (NotSupportedException ex) when (ex.Message.Contains (\"not supported unless it implements IList\"))\n{ /* change HashSet/Set to List<T> */ }","preventionTips":["Use IList-implementing collections (List<T>) or dictionaries for config values.","Avoid HashSet/SortedSet/custom IEnumerable as config property types."],"tags":["configuration","deepcloner","collections","ilist","notsupported"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}