Bug 27127 - Linq.Queryable Expression Count throws Exception
Summary: Linq.Queryable Expression Count throws Exception
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: master
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-02-17 05:20 UTC by Dinesh kumar
Modified: 2015-02-23 05:28 UTC (History)
3 users (show)

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


Attachments
Exception screen shot (526.57 KB, image/png)
2015-02-17 05:20 UTC, Dinesh kumar
Details
Sample to reproduce the issue. (12.36 KB, application/zip)
2015-02-22 23:45 UTC, Dinesh kumar
Details


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 ANSWERED

Description Dinesh kumar 2015-02-17 05:20:35 UTC
Created attachment 9868 [details]
Exception screen shot

I'm creating a user control in Xamarin.IOS datagrid and the attached datasource is converted to AsQueryable and am adding sort descriptions to perform sorting.

The problem i'm facing is am checking the ((queryable)source.count() ==0 ) here i have wirtten a seperate class extension for queryable 

public static int Count(this IQueryable source)
        {
            var sourceType = source.ElementType;
            return (Int32) source.Provider.Execute(
                Expression.Call(
                    typeof (Queryable),
                    "Count",
                    new Type[] {sourceType},
                    new Expression[] {source.Expression}
                    ));
        }
similarly for orderby , elementAt ... etc this code works fine and sorting is performed while i run it in simulator but when it comes to the device am getting exception system.Linq.Queryable doesn't have the so n so method. 

But in the api documentation it has been mentioned that it has support for all this cases. This works fine in Xamarin.Android (both device/ simulator). 

I have attached the screen shot of the issue.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2015-02-17 07:00:18 UTC
Please attach a complete test project we can use to reproduce this issue, the underlying code executed can depend on a lot of factors external to the source lines where the exception occurs (the actual type of 'source' for instance).
Comment 2 Dinesh kumar 2015-02-22 23:45:36 UTC
Created attachment 9971 [details]
Sample to reproduce the issue.

I have attached the sample in which the issue is reproducible and i hope this might be helpful. It would be glad if am getting a fix or a work around asap.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2015-02-23 05:28:39 UTC
You're using dynamic execution to call the Count method (in your QueryableExtensions class); this won't work with the managed linker, since it will not see what you're trying to do, and it will remove the Count method from the Queryable class.

Somehow you must ensure the managed linker keeps the Count methods, and this is one way to do it:

	IEnumerable<string> hack = null;
	if (hack != null) {
		Queryable.Count<string> (null);
		Queryable.Count<string> (null, null);
		hack.AsQueryable ();
	}