SerializationException: Unable to load type required for deserialization

I’m updating a Unity 2018 project to Unity 2019 and deserialization with a BinaryFormatter breaks with assets we had created in Unity 2018.

Here’s the line:

LevelType levelType = (LevelType)bFormatter.Deserialize(stream);

And the error:
System.Runtime.Serialization.SerializationException: Unable to load type LevelType required for deserialization.

LevelType is a simple enum defined in the same file. Is there a change with .NET that causes this issue going from 2018 to 2019? Any ideas how I can fix this or at least step over this enum? Since we use this with player data in our production environment I want to maintain compatibility for the time being (and in the future I will move away from BinaryFormatter).

Thanks to the help of someone on Twitter I discovered the assembly name where these types are defined changed. I was able to write a SerializationBinder to use the right types. Anyone changing assemblies and using a BinaryFormatter should be careful.

3 Likes