The linker does not always play well with serialization. By nature serializers are a bit too dynamic about what they do, making the linker’s job harder than usual. Each of them also has some specific requirements, e.g. for XML serialization:
- a default (parameter-less) constructor must exists;
- properties must have both a getter and a setter
Of course the linker can and will eliminate any .ctor, getter or setters if they are not directly used in your application. The static analysis does not cover how the serializers works – a bit of help is needed.
This is likely the major reason to avoid “Link all” when building MonoTouch applications. But sometimes it can also affect “Link only SDK assemblies”, when the required types are located inside the code that MonoTouch ships. E.g. some fixes were made inside the class libraries for
Rectangle[F] to allow them to work with XML serialization (i.e. ensuring the setters would not be linked away).
However the fixes are generally easy – you simply need to add some
[Preserve] attributes to ensure the serialization contract is not broken by the linker. OTOH it works better when you have the source code and it’s not quite as fun without it.
The good news is that this should be even easier in the future, maybe even automatic for most cases. The linker used by MonoTouch 5.1 (next beta) now understands the basic requirements for the XML and data contract serializers. So code decorated with
[Xml*], with the notable exception of
[DataMember] attributes (and the type’s default constructor) will now be considered as having an implicit
Please let us know if similar scenarios are not fully working when using the linker.