1 year ago

#387607

test-img

DLO

AVRO serialize a c# class with a constructor

My goal is to be able to avro serialize a c# class. I'm currently trying to use Microsoft.Hadoop.Avro to serialize but I can't seem to get it to work as my application throws an exception 'Type 'Animals.Horse' is not supported by the resolver.'. Do you have any idea how to do it right?

Program.cs:

      AvroSerializerSettings settings = new AvroSerializerSettings();
      settings.Resolver = new AvroPublicMemberContractResolver();
      var result = AvroSerializer.Create<Horse>(settings).WriterSchema.ToString();

Horse.cs:

namespace Animals
{
    public class Horse
    {
        public string Name { get; private set; }

        public Horse(string name)
        {
            Name = name ?? throw new ArgumentNullException(nameof(name));
        }
    }
}

Notes: I am aware of this thread: https://www.thecodebuzz.com/avro-serializationexception-type-is-not-supported-by-the-resolver-microsoft-hadoop-avro/ but he's not using a constructor in his domain class. For me it doesn't throw the exception if there wasn't a constructor or if the constructor was empty...

c#

avro

0 Answers

Your Answer

Accepted video resources