Search code examples
c#apache-kafkaavroasp.net-core-3.1confluent-platform

Avro.AvroException: Array does not implement non-generic IList in field


I have .netcore 3.1 api I am using kafka with confluent cloud libraries I am using and their versions are:

schema registry 1.7.0 Serdes 1.3.0

In my schema I have:

{
  "name": "orderLineIds",
  "type": {
    "type": "array",
    "items": "int"
  },
  "default": [],
  "doc": "Associated order line item ids related to this promotion"
}

That generates the following in my class:

        public IList<System.Int32> orderLineIds
    {
        get
        {
            return this._orderLineIds;
        }
        set
        {
            this._orderLineIds = value;
        }
    }

When I try and product event I get the following error:

Avro.AvroException: Array does not implement non-generic IList in field orderLineIds

Am I doing something wrong or missing something from my schema?


Solution

  • I'm using .Net 5 and schema registry 1.8.1 and I was having the same issue. I found that if your collection is null, the Avro serializer will throw this exception as its trying to cast to IList.

    I would double check that orderLineIds always has at least an empty list and is not null.

    Once I did this, my errors went away.