Bug 27497 - Using OnPlatform staticresource crashes on iOS Device
Summary: Using OnPlatform staticresource crashes on iOS Device
Status: RESOLVED DUPLICATE of bug 27201
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.4
Hardware: PC Mac OS
: High normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-02-27 07:24 UTC by Prashant Cholachagudda
Modified: 2015-04-20 20:54 UTC (History)
7 users (show)

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

Test case (159.01 KB, application/zip)
2015-02-27 07:24 UTC, Prashant Cholachagudda

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 Prashant Cholachagudda 2015-02-27 07:24:33 UTC
Created attachment 10078 [details]
Test case

When we use the OnPlatform as static resource the app crashes on the iOS device, but it works on the simulator, an Android, and WP

## Sample code:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Test.MyPage">
			<OnPlatform x:Key="textColor" x:TypeArguments="Color" iOS="Red" Android="#748a9d" WinPhone="#40e0d0" />
			<OnPlatform x:Key="headerFont" x:TypeArguments="Font" iOS="Bold,10" Android="Bold,20" WinPhone="Bold,30" />
	<StackLayout VerticalOptions="StartAndExpand" Orientation="Vertical">
		<Label Font="{StaticResource headerFont}" TextColor="{StaticResource textColor}" Text="Text1" XAlign="Center" />
		<Label Font="{StaticResource headerFont}" TextColor="{StaticResource textColor}" Text="Text2" XAlign="Center" />
		<Label Font="{StaticResource headerFont}" TextColor="{StaticResource textColor}" Text="Text3" XAlign="Center" />

## Stack trace:

System.ExecutionEngineException: Attempting to JIT compile method '(wrapper runtime-invoke) <Module>:runtime_invoke_Font_object (object,intptr,intptr,intptr)' while running with --aot-only.
See http://docs.xamarin.com/ios/about/limitations for more information.
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00044] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:230 ​
Comment 2 Atin 2015-03-05 01:07:55 UTC
I am also getting this issue, application throws exception as soon as launch on iOS device. Hence marking this as Confirmed.

Supplement info:
Exception details: https://gist.github.com/Mohit-Kheterpal/cc7b6cd3f314999d0793
ide logs: https://gist.github.com/Mohit-Kheterpal/d3b6c84c0f0d0a3532d8
application output : https://gist.github.com/Mohit-Kheterpal/7cfde34ddeb3d29929e3

Environment info:
=== Xamarin Studio ===

Version 5.7.2 (build 8)
Installation UUID: 3dbf10c4-ed30-4e55-8a8b-1704777c7b5f
	Mono 3.12.0 ((detached/6235202)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000080

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 862702c
Build date: 2015-02-18 15:19:23-0500

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/apprpject/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		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)

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 507020008
Git revision: 64a4266f0a82f7558472383d8ae66a526b3b881d
Build date: 2015-02-25 11:22:12-05
Xamarin addins: 1cb443ca2dddd9933d748e035560f06cf9c246bd

=== Operating System ===

Mac OS X 10.8.5
Darwin localhost 12.5.0 Darwin Kernel Version 12.5.0
    Sun Sep 29 13:33:47 PDT 2013
    root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-20 20:54:36 UTC
I believe this a duplicate of a Xamarin private bug (bug 27201) that was fixed as of Xamarin.iOS 8.8.1 (released to the stable channel updater channel [1] on March 26). So I am marking it as a duplicate.

> [1] http://developer.xamarin.com/recipes/cross-platform/ide/change_updates_channel/

Here are my observations that suggest that this bug is indeed a precise duplicate of bug 27201.

## The problem _does_ happen on Xamarin.iOS (90e32d0)

On Xamarin.iOS, I can reproduce the exception from comment 0 about attempting to JIT compile something related to "runtime_invoke_Font_object".

## The workaround for Xamarin.iOS (from bug 27201) is successful

Add the following lines to the `AppDelegate` class in the iOS app project:

> [Preserve]
> public static Xamarin.Forms.Font GetFont(object o)
> {
>     return default(Xamarin.Forms.Font);
> }

(Remove the > greater-than symbol from the beginning of each line.)

This stopped the problem in my tests.

## The problem does _not_ happen on Xamarin.iOS (f7736a4)

I can*not* reproduce the exception using the current stable version. The app builds and runs without exception for me on Xamarin.iOS It correctly shows the 3 text fields on screen. 

(I also checked on Xamarin.iOS 8.10, and the results were the same.)

## Version information

### iOS devices

iPad Mini 2, iOS 8.0

### OS X 10.9.5, MacBook Air

Xamarin.iOS, (Business Edition)
Hash: c2c0012
Branch: master
Build date: 2015-04-14 17:26:21-0400

Mono 4.0.0 (detached/d136b79)

Xcode 6.2 (6776), Build 6C131e

*** This bug has been marked as a duplicate of bug 27201 ***