Bug 23355 - Linker strips properties from anonymous types
Summary: Linker strips properties from anonymous types
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: XI 8.0.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2014-09-24 16:23 UTC by Dave Dunkin
Modified: 2018-12-26 17:37 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 23355 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Dave Dunkin 2014-09-24 16:23:30 UTC
When I use the MonoTouch option to "link all assemblies", the anonymous type members get stripped and my code fails at runtime. It passes if the linker is set to link only SDK assemblies. Test case below.

See http://stackoverflow.com/questions/24685034/preserve-anonymous-types-when-linking.

using System;
using System.Collections.Generic;
using System.Reflection;
using MonoTouch.Foundation;
using NUnit.Framework;

namespace LinkerTests.iOS
	[Preserve(AllMembers = true)]
	public class AnonymousTypeTests
		public void Test()
			var str = string.Join(",", AnonymousTypeUtil.GetProperties(new { a = "a", b = "b" }));
			Assert.AreEqual("a=a,b=b", str);

	internal static class AnonymousTypeUtil
		public static IEnumerable<string> GetProperties(object o)
			foreach (var property in o.GetType().GetRuntimeProperties())
				object value = property.GetValue(o);
				yield return property.Name + "=" + value;
Comment 1 Sebastien Pouliot 2014-09-24 16:53:47 UTC
Yes, unused properties are out, but private fields will remain. 

I'll have a look if I can tweak [Preserve] and the anonymous type.
Comment 2 softlion 2016-07-23 00:10:19 UTC
+1 with current beta channel, and there is no way to add [Preserve] to the anonymous type.