Bug 23355 - Linker strips properties from anonymous types
Summary: Linker strips properties from anonymous types
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools (show other bugs)
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: 2016-07-23 00:10 UTC (History)
4 users (show)

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


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.

Note You need to log in before you can comment on or make changes to this bug.