Bug 37563 - Missing Method Exception when converting collection to queryable
Summary: Missing Method Exception when converting collection to queryable
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General (show other bugs)
Version: XI 9.4 (iOS 9.2)
Hardware: PC Windows
: Normal normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2016-01-11 06:03 UTC by Dharmendar
Modified: 2016-12-05 21:23 UTC (History)
12 users (show)

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


Attachments
Attached sample will replicate above mentioned bug (3.46 MB, application/zip)
2016-01-11 06:03 UTC, Dharmendar
Details
Missing Method Exception when converting collection to queryable (95.83 KB, image/png)
2016-05-02 12:31 UTC, Sathya L
Details
Missing Method Exception when converting collection to queryable (11.09 KB, application/x-zip-compressed)
2016-05-10 05:40 UTC, Sathya L
Details
Missing Method Exception when converting collection to queryable (11.09 KB, application/x-zip-compressed)
2016-05-10 06:11 UTC, Sathya L
Details
Latest issue with sample and screen shot attached (3.64 MB, application/x-zip-compressed)
2016-09-19 06:39 UTC, Dharmendar
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 FIXED

Description Dharmendar 2016-01-11 06:03:42 UTC
Created attachment 14524 [details]
Attached sample will replicate above mentioned bug

When converting a obsevable collection to IQueryable using collection.AsQueryable method I'm getting below exception, when linker behavior is "Link Framework SDKs Only". But it is working fine when linker behavior is "Don't Link".

This is working fine in Xamarin.iOS whereas exception occurs only when using iOS in Xamarin.Forms

Configuration Details:
Xamarin Studio : 5.10.1
Xamari.iOS version: 9.4.0.0
XCode 7.2
Mac version 10.11.2

Exception:
System.MissingMethodException: Constructor on type 'System.Linq.EnumerableQuery`1[[System.Int32, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' not found.
  at System.RuntimeType.CreateInstanceImpl (BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) [0x00118] in /Users/builder/data/lanes/2377/73229919/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/rttype.cs:5439
Comment 1 Dharmendar 2016-01-11 14:10:24 UTC
For additional info I have updated xcode to 7.2 and iOS 9.2
Comment 2 Harikrishnan 2016-01-25 06:06:11 UTC
I would like to add some details in this. 
Interestingly this works in iOS 9.1. However when deploying the same sample in other mac machines which has iOS 8.4 and iOS 9.2 the above exception is thrown.

I have attached the configuration of the working machine for your reference:

Working machine Configuration Details:

=== Xamarin Studio ===
Version 5.10.1 (build 6)

Installation UUID: 6b0cdf38-6ea6-4634-add0-5c98ac4d592a

Runtime:

 Mono 4.2.1 (explicit/6dd2d0d)
 GTK+ 2.24.23 (Raleigh theme)
Package version: 402010102
=== Apple Developer Tools ===

Xcode 7.1.1 (9081)
Build 7B1005

=== Xamarin.Mac ===

Version: 2.4.0.109 (Starter Edition)

=== Xamarin.iOS ===

Version: 9.4.0.0 (Business Edition)
Hash: 7322991
Branch: master

=== iOS ==

Version : 9.1(13B137)
Comment 3 Tobias Patton 2016-02-06 00:08:08 UTC
Setting the link options to "none" results in an enormous application bundle, which is likely to be rejected by the app store due to its size. Here's a different workaround:

1. Set linker options to "Link Framework SDKs only".

2. Add the mtouch argument: --linkskip System.Core

This results in a slightly larger application bundle, but not nearly so big.
Comment 4 Harikrishnan 2016-02-22 04:16:36 UTC
Hi @Tabias Patton,

Thanks for the workaround. I was already aware of this and I can confirm that it works as well. But this only bypasses the error and not actually fixes the issue. 

If this is an issue in Xamarin, then can you please confirm it and revert us with an approximate ETA for the fix?
Comment 5 Sebastien Pouliot 2016-02-22 17:35:27 UTC
An easier workaround is to change:

> var enumerable = collection as IEnumerable;

into:

> var enumerable = collection as IEnumerable<int>;

That will tell the linker that the generic version is needed, which might not happen otherwise as reflection is used (in the BCL). There will be no size penalty with the above workaround (unlike a --linkskip).

This will be fixed in a future version of Xamarin.iOS.
Comment 6 Harikrishnan 2016-02-24 04:52:57 UTC
Hi @Sebastien Pouliot,

Thanks for confirming this as a bug. 

Regarding your workaround, It is not applicable in our case as we cannot restrict to have only integer data in a collection in DataGrid.

Anyway I hope the issue will be fixed soon.
Comment 7 Sebastien Pouliot 2016-02-24 07:05:32 UTC
The workaround should not restrict your application in any way.

What it does is make the linker mark `AsQueryable<T>` (instead of the non-generic AsQueryable method) because it see `IEnumerable<T>` as used.

That information is not related to the generic argument, i.e. it's `T` not `int`, that's important in such case, so it will work for any type used. E.g. try adding:

> var c2 = new ObservableCollection<IPlatform> ();
> var e2 = c2 as IEnumerable;
> var q2 = e2.AsQueryable ();

anywhere, even before your current code in App's .ctor. If you use the original sample with:

> var enumerable = collection as IEnumerable;

then it will fail, like it did before (missing code). But if you use the provided workaround

> var enumerable = collection as IEnumerable<int>;

then it will work as expected (for both cases) because the required code will be present.
Comment 8 Sebastien Pouliot 2016-02-24 07:17:00 UTC
Fixed in maccore/master 166fd968b357a7d50189fe62a269b9ea40b45647

Once the bots complete testing successfully this will be backported to `cycle7` for the  next alpha.
Comment 9 Sebastien Pouliot 2016-02-26 18:02:40 UTC
Fix was backported in maccore/cycle7 45762e2442abcac4b8282da3dd72dbf3f75f7e00
Comment 10 Harikrishnan 2016-04-15 09:34:17 UTC
Hi Team,
Has this fix been included in any latest Stable or Pre versions or release?
Comment 11 Sebastien Pouliot 2016-04-15 12:01:57 UTC
@Harikrishnan you can try the fix in the XI 9.8.x version (beta channel).
Comment 12 Sathya L 2016-05-02 12:31:08 UTC
Created attachment 15878 [details]
Missing Method Exception when converting collection to queryable

Attached sample and screenshot will replicate and explain above mentioned bug.

When converting a ObservableCollection to IQueryable using collection.AsQueryable method i am getting exception, when linker behavior is "Link Framework SDKs Only" and setting mtouch arguments set "--linkskip=System.core". But it is working fine use of simulator when linker behavior is "Don't Link" and mtouch arguments set "--linkskip=System.core" but not working in physical devices.
Comment 13 Sebastien Pouliot 2016-05-02 12:37:27 UTC
Either enable the linker (which will remove the new framework) or upgrade to Xcode 7.3 (which includes the latest iOS 9.3 SDK).
Comment 14 Sathya L 2016-05-10 05:40:31 UTC
Created attachment 15952 [details]
Missing Method Exception when converting collection to queryable

Hi Sebastien Pouliot,

Thanks for your information.

We have checked you provided solution in our side. But still we are facing Missing method exception when converting collection to queryable. 

Please find the attached sample will replicate the mentioned issue.

When converting a ObservableCollection to IQueryable using collection.AsQueryable method i am getting exception, when linker behavior is "Link Framework SDKs Only" and setting mtouch arguments set "--linkskip=System.core". But it is working fine use of simulator when linker behavior is "Don't Link" and mtouch arguments set "--linkskip=System.core" but not working in physical devices.
Comment 15 Sathya L 2016-05-10 06:11:17 UTC
Created attachment 15953 [details]
Missing Method Exception when converting collection to queryable

Hi Sebastien Pouliot,

Please ignore the previous update.

Thanks for your information.

We have checked you provided solution in our side. But still we are facing Missing method exception when converting collection to queryable. 

Please find the attached sample will replicate the mentioned issue.

When converting a ObservableCollection to IQueryable using collection.AsQueryable method i am getting exception both simulator and physical device, when linker behavior is "Link Framework SDKs Only" and setting mtouch arguments set "--linkskip=System.core". But it is working fine use of simulator and physsical devices when linker behavior is "Don't Link" and mtouch arguments set "--linkskip=System.core".

Regards,
Sathya
Comment 16 Sebastien Pouliot 2016-05-10 14:48:51 UTC
The attached sample works fine with the release candidate, 9.8.x, on beta channel.

It also works fine on XI 9.6 (stable) if you use the workaround from comment #3. However it's case sensitive so your `--linkskip=System.core` should be `--linkskip=System.Core`
Comment 17 Dharmendar 2016-09-19 06:39:50 UTC
Created attachment 17575 [details]
Latest issue with sample and screen shot attached

Accessing count property of the queryable collection leads to “No method count exist invalid operation exception” in iOS version 9.3
Comment 18 Divakar 2016-11-23 06:57:16 UTC
Hi Team,

Most of our customers are unhappy about this issue. We had reported about this issue before 2 months itself. But still not reply from your side. So, could you please confirm us that when will you fix this issue on your side.
Comment 19 Harikrishnan 2016-11-25 05:27:45 UTC
Hi Team,

Can this issue be prioritized and fixed asap? 

This issue was earlier reported in January 2016 and was fixed only after 3 months from that in the XI 9.8.x version (beta channel) on April.

But it again got broken somewhere. Now the same exception occurs when accessing the IQueryable.Count property which is reported by @dharmendar in September. We have been waiting for the fix for 2 months and is hardly yet to get a reply from your side. Can someone in Xamarin look into this seriously and resolve us the issue asap? 

The workaround is fine, but it is not possible to insist every customer to use the workaround instead of providing a fix. I hope someone in Xamarin will look into this and provide us a reasonable response.
Comment 20 Sebastien Pouliot 2016-12-05 21:23:00 UTC
The original test case still works so this is not a regression. Please do not re-open bugs unless it's a regression (it spam a lot of people in c.c. of bugs and makes the bug history confusing, which can, and has, lead to regressions).

I'm opening a new bug report for the 2nd sample. You can add yourself to it's c.c. list to get updates.

https://bugzilla.xamarin.com/show_bug.cgi?id=49053

As for a workaround you can always add a direct reference to the code (from your library) so that the linker won't remove it (assuming it's similar to the original issue). While this is not ideal (and should be filed as a NEW bug) this is much simpler on your own customers since they won't have any extra steps to implement/configure.