dotnet/machinelearning · error · ArgumentException
String.Format(Strings.MismatchedValueType, typeof(string))
Error message
String.Format(Strings.MismatchedValueType, typeof(string))
What it means
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).
Source
Thrown at src/Microsoft.Data.Analysis/DataFrameColumns/StringDataFrameColumn.cs:467
{
if (value == null)
throw new ArgumentNullException(nameof(value));
StringDataFrameColumn column = inPlace ? this : Clone();
for (long i = 0; i < column.Length; i++)
{
if (column[i] == null)
column[i] = value;
}
return column;
}
protected override DataFrameColumn FillNullsImplementation(object value, bool inPlace)
{
if (value is string valueString)
return FillNulls(valueString, inPlace);
else
throw new ArgumentException(String.Format(Strings.MismatchedValueType, typeof(string)), nameof(value));
}
/// <inheritdoc/>
public new StringDataFrameColumn DropNulls()
{
return (StringDataFrameColumn)DropNullsImplementation();
}
protected override DataFrameColumn DropNullsImplementation()
{
var ret = new StringDataFrameColumn(Name, Length - NullCount);
long j = 0;
for (long i = 0; i < Length; i++)
{
var value = this[i];
if (value != null)View on GitHub (pinned to 7b76e69cf9)
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
Example fix
// before
column.FillNullsImplementation(0, true);
// after
column.FillNullsImplementation("0", true); Defensive patterns
Strategy: type-guard
Validate before calling
if (fillValue is not string) throw new ArgumentException("Fill value for StringDataFrameColumn must be a string"); Type guard
bool IsValidFillValue(object v) => v is string;
Try / catch
try { column.FillNulls(fillValue, true); } catch (ArgumentException) { /* convert fill value and retry */ } Prevention
- Use the typed FillNulls(string, bool) overload
- Branch fill logic on column.DataType
- Keep per-type fill constants ("" for strings, 0 for numbers)
When it happens
Trigger: Calling the polymorphic FillNullsImplementation or object-based FillNulls with an int, double, DateTime, etc. as the fill value.
Common situations: Passing default fill constants (0, empty DateTime) intended for numeric/date columns to a string column; generic fill code that boxes values.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- string.Format(Strings.MismatchedValueType, typeof(string))
- String.Format(Strings.MultipleMismatchedValueType, typeof(lo
- Cannot cast elements of column '{0}' type of {1} to type {2}
- Expected value to be of type {0}
- String.Format(Strings.MismatchedColumnValueType, this.DataTy
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/882a0d4a83ea9e2b.
Report an issue: GitHub.