Bug 21918 - ExecutionEngineException after Xamarin.iOS update: "Not yet supported" at __icall_wrapper_mono_gsharedvt_constrained_call
Summary: ExecutionEngineException after Xamarin.iOS update: "Not yet supported" at __i...
Status: RESOLVED NORESPONSE
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 7.2.6
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-08-07 12:23 UTC by Andrew
Modified: 2016-05-25 00:23 UTC (History)
5 users (show)

Tags:
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 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:
Status:
RESOLVED NORESPONSE

Description Andrew 2014-08-07 12:23:46 UTC
Hi, after installing recent stable Xamarin.iOS and Mono updates, my app started throwing an exception (it worked fine before the update) when is run on a real device (iPhone, 7.1.1):

==================================
Message: Not yet supported.

Exception: System.ExecutionEngineException
Trace:
  at (wrapper managed-to-native) object:__icall_wrapper_mono_gsharedvt_constrained_call (intptr,intptr,intptr,intptr,intptr)
  at MyApp.Client.Forms.FormControlsFactoryBase`1[MyApp.Client.IOs.BaseUiController].RenderNumericField[Decimal,IDecimalProperty] (System.String formControlId, IAttributeMetadata meta, FormMode mode, IRecordProperty value) [0x003c8] in /FormControlsFactoryBase.cs: line 212 
  at MyApp.Client.Forms.FormControlsFactoryBase`1[MyApp.Client.IOs.BaseUiController].CreateControlByMetadata (System.String controlId, System.String controlUId, IAttributeMetadata meta, FormMode mode, MetadataFieldCustomFormat customFormat) [0x00000] in <filename unknown>:0 
==================================

An important note, is that that code runs without exception in the iOS Simulator.

I created a reduced app with same involved interfaces/types, their hierarchy and generic parameters (but without the actual payload code), but unable to reproduce the issue in this reduced app.

May be you can determine the problem from Xamarin.iOS diffs by searching "Not yet supported" string?

Just to let you undestand my app structure:
======================================
using System;
using MonoTouch.UIKit;

namespace HelloWorld1 {
    public class FormControlsFactoryBase<TScreen> where TScreen : class {
        public void RenderNumericField<TValue, TPropertyType>() where TPropertyType : class, IGenericProperty<TValue> where TValue : struct {
            var a = new DecimalProperty(123.456m);
            var b = a.GetAs<TPropertyType>().Value;

            Console.Out.WriteLine("b: " + b);
        }
    }

    public class FormControlsFactory : FormControlsFactoryBase<UIViewController> {
    }

    public interface IProperty {
    }

    public interface IGenericProperty<TValue> : IProperty {
        TValue Value { get; }
    }

    public interface IDecimal : IGenericProperty<decimal> {
    }

    public class Property : IProperty {
    }

    public class DecimalProperty : Property, IDecimal {
        public DecimalProperty(decimal d) {
            Value = d;
        }

        public decimal Value { get; set; }
    }

    public static class Extensions {
        public static TTarget GetAs<TTarget>(this IProperty sourceProperty) where TTarget : class, IProperty {
            return sourceProperty as TTarget;
        }
    }
}

======================================
Usage:

var c = new Container();
c.RenderNumericField<decimal, IDecimal>();

The exception is thrown on this line:

var b = a.GetAs<TPropertyType>().Value;

Project settings are:
SDK 7.0
Link SDK assemblies only
ARMv7 + ARMv7s
Enable generic value type sharing


My current configuration :
=== Xamarin Studio ===

Version 5.2 (build 386)
Installation UUID: f2d8ae39-3eb3-46bf-81fc-1fbdf9af5486
Runtime:
	Mono 3.6.0 ((no/f540f8a)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 306000039

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: 7.2.6.28 (Business Edition)
Hash: 606f31a
Branch: 
Build date: 2014-08-01 15:27:48-0400

=== Xamarin.Android ===

Version: 4.14.0 (Business Edition)
Android SDK: /Users/Andrew/Library/Developer/Xamarin/android-sdk-mac_x86
	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)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Xamarin.Mac ===

Version:

=== Build Information ===

Release ID: 502000386
Git revision: e6a54dee5376e6e7a2d9982695b060fddc09e65d
Build date: 2014-08-04 14:03:28-04
Xamarin addins: 2b5a5c26ac2ee74c6e91a8d24ef44d0ca9cb74d0

=== Operating System ===

Mac OS X 10.9.4
Darwin Andrews-MacBook-Pro.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 1 Andrew 2014-08-07 12:28:12 UTC
After I unchecked "Enable generic value type sharing" option, I start getting this error:

Message: 
Attempting to JIT compile method 'MyApp.Client.Forms.FormControlsFactoryBase`1<MyApp.Client.IOs.BaseUiController>:RenderNumericField<System.Decimal, TenDigits.Data.RecordProperties.IDecimalProperty> (string,TenDigits.Data.Metadata.IAttributeMetadata,MyApp.ClientServer.Interfaces.Forms.FormMode,TenDigits.Data.RecordProperties.IRecordProperty)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.Exception: System.ExecutionEngineException
Trace:
  at MyApp.Client.Forms.FormControlsFactoryBase`1[MyApp.Client.IOs.BaseUiController].CreateControlByMetadata (System.String controlId, System.String controlUId, IAttributeMetadata meta, FormMode mode, MetadataFieldCustomFormat customFormat) [0x00000] in <filename unknown>:0 

It's in the same method, probably caused by the same reason. 
I haven't faced with such AOT-related issues for a year or more, the problem appeared after the recent Xamarin.iOS update (Stable channel).


Hope this helps.
Comment 2 Andrew 2014-08-07 12:58:58 UTC
I simplified the code in my main app (extension method removed) and has found that if I cast to an interface instead of generic type, there's no error. 
Any insights?

Here's a simplified version:

namespace HelloWorld1 {
    public class FormControlsFactoryBase<TScreen> where TScreen : class {
        public object RenderNumericField<TValue, TPropertyType>() 
            where TPropertyType : class, IGenericProperty<TValue> 
            where TValue : struct 
        {

            IProperty a = new DecimalProperty(123.456m);
            
            //-- this works ok
            var b1 = ((IGenericProperty<TValue> )a).Value;            
            
            //-- this throws the error 
            var b2 = ((TPropertyType)a).Value;            

            return new UIView();
        }
    }

    public class FormControlsFactory : FormControlsFactoryBase<UIViewController> {
    }

    public interface IProperty {
    }

    public interface IGenericProperty<TValue> : IProperty {
        TValue Value { get; }
    }

    public interface IDecimal : IGenericProperty<decimal> {
    }

    public class Property : IProperty {
    }

    public class GenericTypeValueProperty<TValue> : Property, IGenericProperty<TValue> {
        public TValue Value { get; set; }
    }

    public class DecimalProperty : GenericTypeValueProperty<decimal>, IDecimal {
        public DecimalProperty(decimal d) {
            Value = d;
        }
    }
}
Comment 3 Sebastien Pouliot 2014-08-07 13:40:11 UTC
I could not duplicate using your code (comment #2) and calling it like this:

			var c = new FormControlsFactoryBase<UIView> ();
			c.RenderNumericField<decimal, IDecimal>();

Please attach a self-contained test case, i.e. that might only happen for some types given to FormControlsFactoryBase.
Comment 4 Andrew 2014-08-07 13:57:05 UTC
Unfortunately I'm unable to create a self-contained test case that clearly does reproduce the issue.
That my simple example contains exactly the same types/interfaces and generic parameters for those in my full application the problem occurs (including NSObject, where they are used), except a few MBytes of source code. 
The problem is clearly caused by generics support in Mono, but I have no reasonable explanation why the simplified code does work. I hoped you can give me some insights when new ExecutionEngineException("Not yet supported") is called.

Actually, as I told above, I found a workaround for myself by casting to interface instead of class. I wonder if it was an expected degradation that will be fixed in the future builds (as the message tells "not YET supported").
Comment 5 Sebastien Pouliot 2014-08-07 14:05:46 UTC
c.c. Zoltan
Comment 6 Zoltan Varga 2014-08-07 16:19:53 UTC
Might be a dup of this, or might be a different issue:
https://bugzilla.xamarin.com/show_bug.cgi?id=18938
Comment 7 Andrew 2014-08-08 04:42:30 UTC
I'm not authorized to view it. Let me know if I can see it somehow.
Comment 8 Mikael Gålfalk 2015-11-24 07:55:55 UTC
I've also experianced this bug. I've thought about isolating this issue into a clean project that pinpoints the issue. But, it was to time consuming so I gave up. Had to revert and install the old version of Xamarin to be able to continue working.

The bug occured at line that created an instance of class using lots of generics. 

System.ExecutionEngineException: Not yet supported. Från monotouch-64/System.Linq.dll
Comment 9 Sebastien Pouliot 2016-05-25 00:23:39 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and re-open the bug report. Thanks!