{"record":{"id":"882a0d4a83ea9e2b","repo":"dotnet/machinelearning","slug":"string-format-strings-mismatchedvaluetype-typeof-882a0d","errorCode":null,"errorMessage":"String.Format(Strings.MismatchedValueType, typeof(string))","messagePattern":"String\\.Format\\(Strings\\.MismatchedValueType, typeof\\(string\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrameColumns/StringDataFrameColumn.cs","lineNumber":467,"sourceCode":"        {\n            if (value == null)\n                throw new ArgumentNullException(nameof(value));\n            StringDataFrameColumn column = inPlace ? this : Clone();\n\n            for (long i = 0; i < column.Length; i++)\n            {\n                if (column[i] == null)\n                    column[i] = value;\n            }\n            return column;\n        }\n\n        protected override DataFrameColumn FillNullsImplementation(object value, bool inPlace)\n        {\n            if (value is string valueString)\n                return FillNulls(valueString, inPlace);\n            else\n                throw new ArgumentException(String.Format(Strings.MismatchedValueType, typeof(string)), nameof(value));\n        }\n\n        /// <inheritdoc/>\n        public new StringDataFrameColumn DropNulls()\n        {\n            return (StringDataFrameColumn)DropNullsImplementation();\n        }\n\n        protected override DataFrameColumn DropNullsImplementation()\n        {\n            var ret = new StringDataFrameColumn(Name, Length - NullCount);\n\n            long j = 0;\n            for (long i = 0; i < Length; i++)\n            {\n                var value = this[i];\n\n                if (value != null)","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrameColumns/StringDataFrameColumn.cs#L449-L485","documentation":"FillNullsImplementation accepts only object values that are string; anything else throws ArgumentException(MismatchedValueType, typeof(string)). It is the object-dispatch layer for the strongly typed FillNulls(string, bool).","triggerScenarios":"Calling the polymorphic FillNullsImplementation or object-based FillNulls with an int, double, DateTime, etc. as the fill value.","commonSituations":"Passing default fill constants (0, empty DateTime) intended for numeric/date columns to a string column; generic fill code that boxes values.","solutions":["Pass a string fill value, e.g. column.FillNulls(\"N/A\", inPlace: true)","Convert the fill value with value.ToString() before calling","Branch on column.DataType and choose the right fill value per column type","Skip string columns in generic fill loops or handle them with string literals"],"exampleFix":"// before\ncolumn.FillNullsImplementation(0, true);\n// after\ncolumn.FillNullsImplementation(\"0\", true);","handlingStrategy":"type-guard","validationCode":"if (fillValue is not string) throw new ArgumentException(\"Fill value for StringDataFrameColumn must be a string\");","typeGuard":"bool IsValidFillValue(object v) => v is string;","tryCatchPattern":"try { column.FillNulls(fillValue, true); } catch (ArgumentException) { /* convert fill value and retry */ }","preventionTips":["Use the typed FillNulls(string, bool) overload","Branch fill logic on column.DataType","Keep per-type fill constants (\"\" for strings, 0 for numbers)"],"tags":["type-mismatch","argumentexception","fillnulls"],"backgroundTag":"type-mismatch","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}