Serialization versus portability

While writing a GIMP# plug-in that can read Paint.NET files we stumbled upon an ugly problem: the Paint.NET developers thought it would be a good idea to use the built-in (binary) serialization features of .NET to save their image files. Of course this is plain stupid for a number of reasons: firstly it will make importing of this file format very difficult for other programs simply because there is no documented file format. Secondly, this leads to portability problems since we can’t know for sure what fields are exactly serialized. It happens that .NET 2.0 serializes a few private member variables that are of course not found when we try to deserialize this stuff with Mono😦 So now we have a GIMP# plug-in that can read Paint.NET files on windows and not on Linux. Sigh.

Conclusion: never ever use binary serialization if you want your files to be used by other programs or on another platform.

I wouldn’t call something stupid until you know the story behind it. Paint.NET v1.0 was written in 15 weeks by a couple of college kids (myself included). One of the things that saved us an enormous amount of time was simply relying on .NET Serialization to define our “file format.” Portability was not a design consideration (nor did we think anybody would even bother downloading the thing when we were done!). The preferred method for other applications to load/save PDN images is to use our PaintDotNet.Data.dll directly.

That said, from looking through the code, it wouldn’t be hard for us to switch to a more ‘portable’ serialization method. We’ve already done this in a few places. We would still use the .NET serialization harness, but we would not rely on the built-in serialization code for non-primitive types. If you e-mail me the data types that are specifically giving you trouble I can look into fixing it for our next release. I think that would be more productive than blogging about it and calling it stupid…

I agree that calling something stupid doesn’t help very much, apart from venting my own frustrations. I’m coming from a background where portability was and is an issue and often it’s very annoying to see yet another solution that works only on platform x.

We did try to use PaintDotNet.Data.dll and that works great on win32. However on Linux we can use this dll, but the deserialization fails in the class in the class System.Collections.CaseInsensitiveComparer because of a missing field “m_compareInfo”. It’s extremely difficult for Mono to handle these kind of exceptions because these are private member variables that aren’t documented.

I very much appreciate your offer to e-mail you and I’m really looking forward to a future in which GIMP and Paint.NET can exchange files.