Bug 26683 - Exception thrown AsQueryable Expression
Summary: Exception thrown AsQueryable Expression
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 8.7.x (iOS 8.2 previews)
Hardware: PC Mac OS
: Normal normal
Target Milestone: 8.10
Assignee: Sebastien Pouliot
Depends on:
Reported: 2015-02-03 07:52 UTC by Dinesh kumar
Modified: 2015-05-05 09:41 UTC (History)
4 users (show)

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

In this simple sample i have created a list with some data as per MVVM model and i have converted the List to IEnumerable and have tried to process the IEnumerable.AsQueryable() -- > Exception Thrown. (16.90 KB, application/zip)
2015-02-03 07:52 UTC, Dinesh kumar

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 Dinesh kumar 2015-02-03 07:52:25 UTC
Created attachment 9619 [details]
In this simple sample i have created a list with some data as per MVVM model and i have converted the List to IEnumerable and have tried to process the IEnumerable.AsQueryable() -- > Exception Thrown.

I was creating a user control similar to a DataGrid and while setting the ItemsSource property am converting the List to IEnumerable and Source.AsQueryable() ; --> this line pops out an exception when i test it with my device i.e

System.MissingMethodException: No constructor found for System.Linq.QueryableEnumerable1[[SfDataGridRowPanelCellsDrawing.OrderInfo, Sample, Version=, Culture=neutral, PublicKeyToken=null]]::.ctor(System.Collections.Generic.List1[SfDataGridRowPanelCellsDrawing.OrderInfo])
at System.Activator.CreateInstance (System.Type type, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x0013b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:301
at System.Activator.CreateInstance (System.Type type, System.Object[] args, System.Object[] activationAttributes) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:232
at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:227
at System.Linq.Queryable.AsQueryable (IEnumerable source) [0x00047] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/
at Linq.Android.QueryableCollectionView..ctor (IEnumerable source) [0x00011] in /Users/labuser/Projects/SfGrid.IOS/Linq.IOS/CollectionView/QueryableCollectionView.cs:51
at SfGrid.IOS.GridQueryableCollectionViewWrapper..ctor (IEnumerable source, SfGrid.IOS.SfDataGrid grid) [0x00000] in /Users/labuser/Projects/SfGrid.IOS/SfGrid.IOS/GridQueryableCollectionViewWrapper.cs:12
at SfGrid.IOS.SfDataGrid.CreateCollectionViewAdv (IEnumerable source, SfGrid.IOS.SfDataGrid dataGrid) [0x0000c] in /Users/labuser/Projects/SfGrid.IOS/SfGrid.IOS/SfDataGrid.cs:90
at SfGrid.IOS.SfDataGrid.CreateCollectionView (System.Object itemsSource) [0x0000b] in /Users/labuser/Projects/SfGrid.IOS/SfGrid.IOS/SfDataGrid.cs:76
at SfGrid.IOS.SfDataGrid.SetSourceList (System.Object itemsSource) [0x0000a] in /Users/labuser/Projects/SfGrid.IOS/SfGrid.IOS/SfDataGrid.cs:68
at Sample.SampleController.ViewDidLoad () [0x0002d] in /Users/labuser/Projects/SfGrid.IOS/Sample/SampleController.cs:42
at at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
at UIKit.UIWindow.MakeKeyAndVisible () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/build/native/UIKit/UIWindow.g.cs:247
at Sample.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x0002c] in /Users/labuser/Projects/SfGrid.IOS/Sample/AppDelegate.cs:35
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:45
at Sample.Application.Main (System.String[] args) [0x00008] in /Users/labuser/Projects/SfGrid.IOS/Sample/Main.cs:17

but when used in Simulator it doesn't . This issue replicable with a simple Ienumerable.AsQueryable () i think this must be a break in your Fixes. 

https://bugzilla.xamarin.com/show_bug.cgi?id=3028 - this link shows up a similar bug which am facing now. 

I have attached a simple sample for reproducing the issue. 

Note : Unified IOS App (8.1) Xmaarin Studio Version - 5.7 (Build 661) Device - iphone 5s , Ipad Air.
Comment 1 Sebastien Pouliot 2015-02-03 09:04:37 UTC
It seems the linker removes the required method as it's invoked by reflection (see Activator.CreateInstance in the stack trace).

I'll have a look why/when this changed and give you a workaround.
Comment 2 Sebastien Pouliot 2015-02-03 10:17:26 UTC
The required information is (statically) available to the linker when the generic versions of the API are used. E.g.

	var obj = new ViewModel ().OrdersInfo;
	var q = obj.AsQueryable<OrderInfo> ();

works fine.

Another workaround is telling the linker what you need, e.g. if you add this:

	System.Collections.Generic.IEnumerable<OrderInfo> hack = null;
	if (hack != null)
		hack.AsQueryable ();

then your existing code will also work (as the linker's static analysis would have identified the requirement members).

I'll look at teaching the linker about the non-generic case.
Comment 3 Sebastien Pouliot 2015-02-03 11:58:14 UTC
Fixed in master / 89f1ce726ed60519bdff655601c2dbf31c0374ec
Comment 4 Dinesh kumar 2015-02-05 12:22:12 UTC
Hi ,

Thanks for the reply , but the proposed work around doesn't suit for the use case in our end because it's a kind of processing the data that we are attaching it to the user control , as it's not possible to make Queryable<T> or to know the underlying collection {whereas in the reported sample OrderInfo] so it would be great if you're rolling out the fix for the issue asap.
Comment 5 Sebastien Pouliot 2015-02-05 13:40:11 UTC
There are three workarounds. The first two (linkskip and using the generic overload) might not be well suited for you but the 3rd one should not be a problem.

What's needed is IEnumerable<T>, not of a specific type (e.g. OrderInfo ), so you can use `string` to have the linker preserve the required code. IOW using this, anywhere in your app

   System.Collections.Generic.IEnumerable<string> hack = null;
    if (hack != null)
        hack.AsQueryable ();

will do the job.
Comment 6 Akhilesh kumar 2015-05-05 09:41:38 UTC
I have checked this issue with attached test project and I am able to reproduce the issue with XI, on deploying application on device, it throws exception.

However, when I tried same with XI then application deploys successfully without any exception.

Screencast: http://screencast.com/t/4Cij86ryx

Hence closing this issue. 

Please let me know if I have to check any thing else to verify this issue.

Device info: iPAD mini iOS 8.0.2

Environment info:

=== Xamarin Studio ===

Version 5.9 (build 464)
Installation UUID: 91997f85-0008-4b4c-9f53-c7f991fcdae3
	Mono 4.0.1 ((detached/5a0b19f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010024

=== Apple Developer Tools ===

Xcode 6.3 (7569)
Build 6D570

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 1b48440
Branch: master
Build date: 2015-05-04 17:01:32-0400

=== Build Information ===

Release ID: 509000464
Git revision: 97f3c43266a4abe2dff0a31b1afb976de897d099
Build date: 2015-05-04 10:06:54-04
Xamarin addins: 438f3e4b8352e006958552de07c6f54770c9233c

=== Operating System ===

Mac OS X 10.10.2
Darwin Apples-iMac.local 14.1.0 Darwin Kernel Version 14.1.0
    Mon Dec 22 23:10:38 PST 2014
    root:xnu-2782.10.72~2/RELEASE_X86_64 x86_64