Add detailed error message for invalid serialization

Solves gh-1155