Bug 1017 - Exception Attempting to JIT compile method 'System.Linq.Enumerable:OfType'
Summary: Exception Attempting to JIT compile method 'System.Linq.Enumerable:OfType'
Status: RESOLVED DUPLICATE of bug 587
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 4.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-09-23 10:59 UTC by AndyW
Modified: 2011-09-29 10:06 UTC (History)
2 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 DUPLICATE of bug 587

Description AndyW 2011-09-23 10:59:36 UTC
Just updated to the latest stable MonoTouch (4.2.1) from the previous stable release.

Unfortunately code that did work is now throwing a JIT. 

I'm using Linq to count the number of IMyTypes in an IEnumberable.

var count = _object.Entries.OfType<IMyType>().LongCount(); 

But this is now throwing a JIT: 

System.ExecutionEngineException has been thrown 

Attempting to JIT compile method 
'System.Linq.Enumerable:OfType<IMyType>
(System.Collections.IEnumerable)' while running with --aot-only. 

_object = a custom object in a separate MonoTouch library.

_object.Entries = IEnumerable<IMyBaseType> where objects are yield'd back

Linker setting for devices, is set to "Don't Link".

I've tried to create a sample project outside of my main project, but cannot reproduce. Sorry.
Comment 1 Sebastien Pouliot 2011-09-23 11:19:43 UTC
> Linker setting for devices, is set to "Don't Link".

Can you try it with the default value, i.e. "Link SDK assemblies" ?

It could be related to bug #587 which is already fixed and only occured when "Don't Link" is used.

>I've tried to create a sample project outside of my main project, but cannot
>reproduce. Sorry.

Maybe your sample project is using "Link SDK assemblies" ?


If that still give you the same error then can you please give us the complete definition of IMyBaseType so we can try to build a test case out of this.
Comment 2 AndyW 2011-09-23 12:50:45 UTC
My sample project is using "Don't Link".

Unfortunately I can't test with "Link SDK Assemblies" as this links away stuff I need to get the above JIT.

I'm sorry but I can't post the code surrounding IMyBaseType, its a very complex set of propriety code, this is probably why I'm having trouble recreating in a test project.
Comment 3 Sebastien Pouliot 2011-09-23 13:40:47 UTC
>Unfortunately code that did work is now throwing a JIT. 
...
> Unfortunately I can't test with "Link SDK Assemblies" as this links away stuff
>I need to get the above JIT.

In the above you mean exception, right ? (i.e. JIT means Just In Time).

Just to make sure I understand this properly (please correct me if I'm wrong):

a) you get the exception (form the original description) if you use "Don't link";

b) you're getting another error/crash/exception when using "Link SDK assemblies".

If (b) is true then this is another bug. The "Link SDK assemblies" option should only remove code from the assemblies shipped by MonoTouch. If it fails to build (or execute) your application then it's a bug and it should be reported in (a separate) bug report so it can be fixed properly for everyone.

> I'm sorry but I can't post the code surrounding IMyBaseType, its a very complex
> set of propriety code,

Ok, let clear up the above first. If we block, later, on the resolution then we can look at signing an NDA so you can share (privately) more details with us.
Comment 4 AndyW 2011-09-23 14:06:12 UTC
Sorry for causing confusion. Yes I do mean Exception.

A. Yes that is correct.

B. When I use "Link SDK Assemblies" it appears that some code is removed from from your libraries, I get a mixture of "Linked Away" and "Not Supported". This could be down to the way we do things in our libraries.  This has always been the case since we started using MonoTouch, hence the reason we are set to "Don't Link". 

Thanks
Comment 5 Sebastien Pouliot 2011-09-23 14:19:00 UTC
Ok, about (B) you should fill a bug report with them. It could be bugs or it could be stuff that is removed for specific reasons - i.e. some features that are not supported by iOS devices (e.g. they require the JIT to be available) are removed by the linker. Disabling the linker will hide the issue(s) but it won't allow the device to use the feature(s) and also makes your application a lot larger than it needs to be.

Back to (A) you could try to reproduce the issue by adding:

var count = _object.Entries.OfType<IMyType>().LongCount(); 

or somthing similar that will do a "OfType<IMyType>().LongCount();" inside your Main method and use the "Link SDK assemblies". Since it would be executed very earlier there's a good chance it would not trigger the issues you have using (B). If you get past that line then we'll know (A) is bug #587, otherwise we'll know this needs further investigation.
Comment 6 AndyW 2011-09-28 08:00:45 UTC
Sorry for the delay, I cannot get access to this Linq query early enough.

#767 seems similar to this, and on further testing it appears some of my other Linq queries fail, even with "Don't Link".
Comment 7 Sebastien Pouliot 2011-09-28 09:31:32 UTC
> I cannot get access to this Linq query early enough.

Nothing is executed before the Main method (even your FinishedLaunching method) but since you could make sure it's not (totally) related to #587 then it's not really important anymore.

> #767 seems similar to this, and on further testing it appears some of my other
> Linq queries fail, even with "Don't Link".

Using "Don't link" was a workaround for bug #587 (fixed in upcoming 4.2.2) but it won't solve issues, like #767, that hits limitations of generic usage under AOT.

http://ios.xamarin.com/Documentation/Limitations#Limited_Generics_Support

You can workaround them (some cases are easier than others) and we can also help you if needed (but that will require access to the source code causing the exception). You can contact support@xamarin.com to ask for the NDA document.
Comment 8 AndyW 2011-09-28 10:05:41 UTC
All my Linq queries did work prior to MonoTouch 4.2, is there a link anywhere to download the previous stable release?
Comment 10 Sebastien Pouliot 2011-09-28 10:59:17 UTC
Look for "Product Download and Activation Self Service" on http://support.xamarin.com/

You might also want to try 4.2.2 (to be released soon) since that will remove any doubt about bug #587.
Comment 11 AndyW 2011-09-28 12:31:08 UTC
Its possible that this is bug #587 as I have reproduced (with less complexity) in a test app. 

When set to "Don't Link" the code fails, but when set to "Link SDK" it works.

I shall await 4.2.2 and check my main code and report back.



using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace test
{
	public class Application
	{
		static void Main (string[] args)
		{
			UIApplication.Main (args);
		}
	}
	
	class Things
	{
		public string Property;
	}
	
	// The name AppDelegate is referenced in the MainWindow.xib file.
	public partial class AppDelegate : UIApplicationDelegate
	{
		Dictionary<string, List<Things>> _thingys = new Dictionary<string, List<Things>>();
		
		// This method is invoked when the application has loaded its UI and its ready to run
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			// If you have defined a view, add it here:
			// window.AddSubview (navigationController.View);
			var things1 = new List<Things>();
			things1.Add(new Things{Property = "1,1"} );
			things1.Add(new Things{Property = "1,2"} );
			
			_thingys.Add("Things1", things1);
			
			var things2 = new List<Things>();
			things2.Add(new Things{Property = "2,1"} );
			things2.Add(new Things{Property = "2,2"} );
			_thingys.Add("Things2", things2);
			
			Console.WriteLine(_thingys.Values.ElementAt(1).Count());
				
			window.MakeKeyAndVisible();
	
			return true;
		}
	
		// This method is required in iPhoneOS 3.0
		public override void OnActivated (UIApplication application)
		{
		}
	}
}
Comment 12 AndyW 2011-09-29 10:06:29 UTC
MonoTouch 4.2.2 fixes this.

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