Search Unity

BinaryFormatter and class namespace change

Discussion in 'Scripting' started by Korno, Oct 10, 2015.

  1. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    Hey,

    So I know that the BinaryFormatter embeds the fully qualified class name when it serializes objects. This is fine, I am not complaining about this. I also know you can avoid this by setting AssemblyFormat to simple when you create the formatter. However I didn't do this as I have objects in the same assembly with the same name in different namespaces.

    My problem is that I am reorganizing my project at the moment and would love to move a class into a new namespace. However, I have data already saved with the class in its old namespace and this is going to throw up a huge cannot create type exception the next time I attempt to load the data.

    Recreating this data is not an option ( a lot of it is end user created) I have read about SerializationBinder to use BindToName to provide custom type mapping - but this seems to only be in .NET 4 so we cant use it....

    I suppose I could create a temporary class that lives in the same namespace as the old class which contains the same fields and it just silently creates a new object in the new namespace and overwrites the old data but is that really required?

    Any better solutions? Are there any hooks I can use to modify the BinaryFormatters execution?
     
    Last edited: Oct 10, 2015