{"record":{"id":"2c24ac52790bfaa3","repo":"dotnet/machinelearning","slug":"strings-immutablecolumn","errorCode":null,"errorMessage":"Strings.ImmutableColumn","messagePattern":"Strings\\.ImmutableColumn","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrameColumns/ArrowStringDataFrameColumn.cs","lineNumber":278,"sourceCode":"            {\n                fixed (byte* data = &MemoryMarshal.GetReference(bytes))\n                    return Encoding.UTF8.GetString(data, bytes.Length);\n            }\n        }\n\n        /// <inheritdoc/>\n        protected override IReadOnlyList<object> GetValues(long startIndex, int length)\n        {\n            var ret = new List<object>();\n            while (ret.Count < length)\n            {\n                ret.Add(GetValueImplementation(startIndex++));\n            }\n            return ret;\n        }\n\n        /// <inheritdoc/>\n        protected override void SetValue(long rowIndex, object value) => throw new NotSupportedException(Strings.ImmutableColumn);\n\n\n        /// <summary>\n        /// Indexer to get values. This is an immutable column\n        /// </summary>\n        /// <param name=\"rowIndex\">Zero based row index</param>\n        /// <returns>The value stored at this <paramref name=\"rowIndex\"/></returns>\n        public new string this[long rowIndex]\n        {\n            get => GetValueImplementation(rowIndex);\n            set => throw new NotSupportedException(Strings.ImmutableColumn);\n        }\n\n        /// <summary>\n        /// Returns <paramref name=\"length\"/> number of values starting from <paramref name=\"startIndex\"/>.\n        /// </summary>\n        /// <param name=\"startIndex\">The index of the first value to return.</param>\n        /// <param name=\"length\">The number of values to return starting from <paramref name=\"startIndex\"/></param>","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrameColumns/ArrowStringDataFrameColumn.cs#L260-L296","documentation":"ArrowStringDataFrameColumn is immutable: the protected SetValue override always throws NotSupportedException(Strings.ImmutableColumn). Any API that mutates a single value by row index (the base-class indexer setter, FillWith value assignment paths) hits this throw. The column only supports append-style construction and reads.","triggerScenarios":"Assigning through the base DataFrameColumn indexer ((DataFrameColumn)col)[rowIndex] = value, calling base-class APIs that call SetValue (e.g. certain Fill/apply implementations), or any mutation helper built on SetValue.","commonSituations":"Treating an Arrow-backed column (loaded from Arrow IPC/Feather) like a regular editable PrimitiveDataFrameColumn; generic code written against DataFrameColumn that mutates in place.","solutions":["Do not mutate in place: build a new column with modified values and replace it in the collection.","Use a regular StringDataFrameColumn (or PrimitiveDataFrameColumn) when in-place edits are required.","Route writes through Append (on a fresh column) rather than SetValue-based APIs.","Wrap mutation logic in a check: if (col is ArrowStringDataFrameColumn) clone-and-replace, else mutate."],"exampleFix":"// before\n((DataFrameColumn)df.Columns[\"s\"])[5] = \"new\"; // NotSupportedException\n\n// after\nvar values = Enumerable.Range(0, (int)df.Columns[\"s\"].Length)\n    .Select(i => i == 5 ? \"new\" : df.Columns[\"s\"][i].ToString());\ndf[\"s\"] = new StringDataFrameColumn(\"s\", values);","handlingStrategy":"type-guard","validationCode":"if (df.Columns[name] is ArrowStringDataFrameColumn)\n    throw new InvalidOperationException(\"Column is immutable; replace instead of mutating\");","typeGuard":"static bool IsMutableColumn(DataFrameColumn c) => c is not ArrowStringDataFrameColumn;","tryCatchPattern":"try { baseCol[rowIndex] = value; }\ncatch (NotSupportedException) { /* rebuild column with updated value and reassign */ }","preventionTips":["Treat Arrow-backed columns as read-only","Use StringDataFrameColumn for editable string data","Centralize mutation behind a helper that clones-and-replaces","Check column type before in-place edits"],"tags":["dotnet","dataframe","immutable","not-supported"],"backgroundTag":"unsupported-operation","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}