Bug 3735

Summary: Attempting to JIT compile method: using Linq's "Any" fails on the device
Product: iOS Reporter: René Ruppert <rene>
Component: XI runtimeAssignee: Bugzilla <bugzilla>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+monotouch, rene, sebastien
Priority: ---    
Version: 5.0   
Target Milestone: Untriaged   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description René Ruppert 2012-03-02 17:42:41 UTC
Monotouch 5.2.6.

Getting JIT exception using "Any". Exception and code below.

System.ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-managed) BLAPI3WrapperClassicWSServiceRef.DownloadType[]:System.Collections.Generic.IEnumerable`1.GetEnumerator ()' while running with --aot-only.

Code snippet:

List<DOWNLOAD_TYPE> aDownloadTypes = new List<DOWNLOAD_TYPE>();
			if ( aTypes != null )
			{
				if ( aTypes.Any( eType => eType == DownloadType.BrainmarkImage || eType == DownloadType.BrainmarkPDF || eType == DownloadType.BrainmarkPDFRMS ) )
				{
					aDownloadTypes.Add( DOWNLOAD_TYPE.Brainmark );
				}
			}
Comment 1 Sebastien Pouliot 2012-03-02 19:10:55 UTC
Hello René. We need the type definitions to duplicate the issue (since it will, internally, make a huge difference in the code generation and AOT compilation).

E.g. what do DOWNLOAD_TYPE and DownloadType look likes ? enums ?
Comment 2 René Ruppert 2012-03-03 07:20:54 UTC
Yes, they are enums. Integer, no flags attribute.
Can you think of a work around that allows keeping the "Any"?
Comment 3 Sebastien Pouliot 2012-03-03 12:50:21 UTC
I still need the exact details (you can mark them private if you need). E.g. this works for me:

			List<Environment.SpecialFolder> list = new List<Environment.SpecialFolder> () {
				Environment.SpecialFolder.ApplicationData,
				Environment.SpecialFolder.CommonApplicationData
			};
			Assert.True (list.Any (folder => folder == Environment.SpecialFolder.ApplicationData));
Comment 5 Sebastien Pouliot 2012-03-05 09:52:53 UTC
So it worked for me because I used the following for `aTypes` (same for my original test case):

List<DownloadType> aTypes = new List<DownloadType>() { DownloadType.BrainmarkPDF };

but I get the exception if use:

DownloadType [] aTypes = new DownloadType [] { DownloadType.BrainmarkPDF };

(which I assume is what you have) so the workaround is to use:

var lTypes = new List<DownloadType> (aTypes);

over your existing array. That will make it clear that the AOT compiler needs to bring the related enumerator type/methods in your final application.
Comment 6 René Ruppert 2012-03-05 10:03:29 UTC
But is there a real fix for one of the next MT releases the will work without the workaround?
Comment 7 Sebastien Pouliot 2012-03-05 10:22:16 UTC
Nothing immediate, as this is part of the generic limitations [1], but the workaround will still work if/when this gets fixed.

This issue, like others, are being tracked - i.e. both the failing case and the workaround are included in our test suite. So it's a constant reminder...

[1] http://docs.xamarin.com/ios/about/limitations#Limited_Generics_Support