Bug 26752 - Xamarin.Forms crashes on iOS when loading attributes with Reflection
Summary: Xamarin.Forms crashes on iOS when loading attributes with Reflection
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 8.6.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2015-02-04 15:23 UTC by James
Modified: 2015-02-10 21:06 UTC (History)
6 users (show)

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

Project Exhibiting Issue (166.45 KB, application/zip)
2015-02-04 15:23 UTC, James

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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description James 2015-02-04 15:23:10 UTC
Created attachment 9649 [details]
Project Exhibiting Issue

As per a customer:

See the attached project project that exhibits the crash on iOS devices.

To Reproduce:
Just compile and deploy the project. 
It shows a button “Press me” that calls the necessary code. 
It runs fine on Android, WinPhone and the iOS simulator.

Confirmed to crash on iPad.
It seems that the framework has trouble to load a type while getting attributes via reflection. It may be that this is related to the project structure as well (maybe the linker is involved):

The version you now have builds the portable library to the bin folder and the iOS-application to bin\iphone. This exhibits the problem. If I build everything into the same folder, the build succeeds on the iPhone.
Comment 1 Sadik Ali 2015-02-05 03:38:48 UTC
I have checked this issue and able to reproduce this. To reproduce this issue I have followed the steps and instruction provided in bug description.
I observed that after deploying the application on device, and then pressing the button the application get crashed. Please refer the screencast for the same.


Application Out: https://gist.github.com/Rajneesh360Logica/91cff9bfd23acbfcd2e2
Ide logs: https://gist.github.com/Rajneesh360Logica/f0c33ba58e9ac547fc18
Build Output: https://gist.github.com/Rajneesh360Logica/d4d969080df7a31bdb79
Device Logs: https://gist.github.com/Rajneesh360Logica/5048655adb98507661d7
iOS designer Logs: https://gist.github.com/Rajneesh360Logica/2ff78469efcc0f3cb975

Environment Info:

=== Xamarin Studio ===

Xamarin.Forms Version:

Version 5.7.1 (build 17)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 3b3ef43
Build date: 2015-01-24 09:42:21-0500

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 507010017
Git revision: 0bc7d3550b6b088ac25b08dcf7bbe73bcc8658b3
Build date: 2015-02-03 19:43:29-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 2 Jason Smith [MSFT] 2015-02-09 19:36:39 UTC
This looks to be an issue unrelated to forms, redirecting to ios.
Comment 3 Sebastien Pouliot 2015-02-10 11:28:07 UTC
> (maybe the linker is involved)

FYI that's an easy assertion to confirm/deny. You can enable the linker on the simulator (fails) and disable it on devices (works).

> Could not load type System.String, System.Runtime, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a while decoding custom attribute

^ that's a reference to a facade assembly (not where the type resides).
Comment 4 Sebastien Pouliot 2015-02-10 12:12:55 UTC
So there's an extra reference to `System.Runtime` (which has not been resolved to `mscorlib` since it's looking for `System.String`) that needs to be tracked down. It's likely a missing case (custom attributes only?) where our PCL support is incomplete.

Note: setting the linker to "Link all" solves the issue (but you might run into different issues).
Comment 5 Sebastien Pouliot 2015-02-10 14:36:49 UTC
> [MessageProperty(0, TypeInBuffer = typeof(string))]

since this is inside a PCL assembly the custom attribute is encoded with a reference to System.Runtime (not mscorlib) as the assembly that provides `string`. The way custom attributes are encoded means this is not a _normal_ type reference (and not one being resolved). 

In general "Link SDK" does no (normally) change user code except for some stuff (like forwarding). That code is different from "Link all" and (I'm pretty sure) is not custom attribute aware.
Comment 6 Sebastien Pouliot 2015-02-10 21:06:52 UTC
Fixed in mono/master d07822286c01a072a36f8cfd678abb99b41e27f3
and backported to mono/mono-3.12.0-branch 53274401f4e10a3c494cb88405bcf324fb0d0271 for XI 8.10