You are taking a string reference and try to cast it to an object array, which causes the InvalidCastException.
Your SqlFunction1
method returns an array of strings, so the FillRow
method will be called with a string reference. Cast the object reference back to string, and then create a SqlString
value from it:
private static void FillRow(Object obj, out SqlString str) {
string row = (string)obj;
str = new SqlString(row);
}