ch-robinson / dotnet-avro

An Avro implementation for .NET
https://engineering.chrobinson.com/dotnet-avro/
MIT License
134 stars 49 forks source link

Union with null and multiple selected types throws exception when serializing null. #237

Closed darren-clark closed 1 year ago

darren-clark commented 1 year ago

Using a derived BinaryUnionSerializerBuilderCase to override SelectType with specified subclasses, serializing null will fail, throwing "Unexpected type encountered serializing..."

This is due to the check for null being inside each case, which is only executed when Expression.TypeIs returns true, which it will not for null values.

If there is only one case other than null, the serializer works as expected, because there is no type check.

dstelljes commented 1 year ago

Thanks for the report and fix, @darren-clark! We’ll release this with 9.3.1 later today.