I am creating Confluent kafka producer in C# .Net environment with Avro array schema. While sending request I am getting below error.
> Avro.AvroException: GenericRecord required to write against record schema but found Avro.Generic.GenericRecord \n at Avro.Generic.DefaultWriter.EnsureRecordObject(RecordSchema s, Object value) \n at Avro.Generic.DefaultWriter.WriteRecord(RecordSchema schema, Object value, Encoder encoder) \n at Avro.Generic.DefaultWriter.Write(Schema schema, Object value, Encoder encoder) \n at Avro.Generic.DefaultWriter.WriteArray(ArraySchema schema, Object value, Encoder encoder) \n at Avro.Generic.DefaultWriter.Write(Schema schema, Object value, Encoder encoder) \n at Avro.Generic.DefaultWriter.WriteRecord(RecordSchema schema, Object value, Encoder encoder)
Avro Schema
var s = (RecordSchema)RecordSchema.Parse(
@{
"name": "StaticDataNotification",
"type": "record",
"namespace": "KafkaName",
"fields": [
{
"name": "UniqueID","type": "string"
},
{
"name": "DataList",
"type": {
"type": "array",
"items":{
"name": "DataList_record",
"type":"record",
"fields": [
{
"name": "FieldName","type": "string"
},
{
"name": "OldValue","type": "string"
}
]
}
}
}
]
}
var child = (RecordSchema)RecordSchema.Parse(
@{
"name": "DataList_record",
"type":"record",
"fields": [
{
"name": "FieldName","type": "string"
},
{
"name": "OldValue","type": "string"
}
]
}
C# Code:
var recordStaticData = new GenericRecord(s);
recordStaticData.Add(“UniqueID”,“123456”);List genericRecords = new List();
for (int i = 0; i < 3; i++)
{
GenericRecord StaticList = new GenericRecord(child);
StaticList.Add(“FieldName”, “Name”);
StaticList.Add(“OldValue”, i.ToString());
genericRecords.Add(StaticList);
}
recordStaticData.Add(“DataList”,genericRecords.ToArray());var dr = producer.ProduceAsync(“Topic”, new Message<string,GenericRecord>{ Key = System.Guid.NewGuid().ToString(“N”), Value = recordStaticData });