Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / .NET

MonoTouch – MonoDevelop Linker Hell

4.67/5 (3 votes)
27 Feb 2013CPOL1 min read 10K  
One of the first learning experiences I had when I dove into development was the linking functionality built into MonoTouch.

OverDog is my first project which uses Xamarin, a cross-platform tool for creating applications in C#. I've nothing but adoration for the platform, but one of the first learning experiences I had when I dove into development was the linking functionality built into MonoTouch.

The linker basically reads your applications possible execution paths and removes unused code. I was unaware of this functionality when I started development, but soon ran into problems when trying to deserialize some JSON into a class I created to hold user data. The JSON.NET library was telling me that my class was missing a default constructor, which simply wasn't the case. What I came to realize was that the linker was pulling out most of my data structures!

I alleviated the problem by attaching a [Preserve] compiler tag to each of my data model classes. To prevent all members of the class from being touched by the linker, you simply add an AllMembers argument:

C#
[Preserve(AllMembers=true)]
public class User
{
...
}

That solved my issues with the linker. This was a huge headache without any obvious acknowledgment by MonoTouch that this was occurring. What was confusing to me is the fact that my application's execution paths should have included my model data classes. The fact that they were being chopped up by the linker seems to be a bug.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)