Q: ArcObjects: Convert Feature to JSON I need to get the JSON from a feature using ArcObjects. According to  I tried to following code, but it does not work:
var jsonWriter = new JSONWriterClass();
jsonWriter.WriteToString();

var jsonSerializer = (IExternalSerializerGdb2) new JSONSerializerGdbClass();
var options = new GeometryResultOptionsClass();
var fieldIndexes = Enumerable.Range(0, feature.Fields.FieldCount).ToArray();
serializer.WriteRow("", feature, feature.Fields, fieldIndexes, options);
var json = Encoding.UTF8.GetString(jsonWriter.GetStringBuffer());

I allways get the error in the line serializer.WriteRow("", feature, feature.Fields, fieldIndexes, options):

Value does not fall within the expected range. (Source: ESRI.ArcGIS.Geodatabase)

Does anybody know how to call the WriteRow(...) method correctly

A: You have forgotten to initialize the serializer. This code might work, at least it did for me:
var jsonWriter = new JSONWriterClass();
jsonWriter.WriteToString();

var jsonSerializer = new JSONSerializerGdbClass();
jsonSerializer.InitSerializer(jsonWriter, null); // <--
var options = new GeometryResultOptionsClass();
var fieldIndexes = Enumerable.Range(0, feature.Fields.FieldCount).ToArray();
((IExternalSerializerGdb2)serializer).WriteRow("", feature, feature.Fields, fieldIndexes, options);
var json = Encoding.UTF8.GetString(jsonWriter.GetStringBuffer());

