Protobuf metadata validation is not thread safe. This error is "rare", but a lot happens in huge serializations that run in parallel. I had this exact error in my project where I serialize about 70 million objects. You can fix this by creating AHEAD serialization metadata:
Serializer.PrepareSerializer<YourCustomType1>(); Serializer.PrepareSerializer<YourCustomType2>();
Make this code somewhere ahead of serialization, possibly a static constructor, for each of your custom types that are serialized.
You can also try increasing the Protobuf metadata validation timeout to try to help you, but in the event of a true deadlock in the Protobuf code, this simply delays your exception:
// Initialize Protobuf Serializer for 5 minutes of wait in the case of long-waiting locks RuntimeTypeModel.Default.MetadataTimeoutMilliseconds = 300000;
Haney
source share