xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

Exception with System.Linq.Queryble while setting Linker behavior other than Don't link in iOS platform #7586

Closed KarthikRajaAKR closed 5 years ago

KarthikRajaAKR commented 5 years ago

Description

In our custom control, we are using QuerybleExtensions to populate PickerItem, which is working if we set Linker behavior to Don't link but if we set Link framework sdks only or Link All, it shows below exception on loading view.

No generic method 'Select' on type 'System.Linq.Queryable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.

Please check the issue and provide the solution since which breaks major feature in our control.

Steps to Reproduce

  1. Run the attached sample with Linker behavior Don't Link, it will work fine
  2. If you run the sample with Linker behavior Link framwork SDKs only, an exception will be thrown on loading initial view

Expected Behavior

Control need to be rendered without crash.

Actual Behavior

Exception occurs on loading initial view itself.

Basic Information

Reproduction Link

DataForm.zip

hartez commented 5 years ago

@KarthikRajaAKR This is not a Forms bug, but an issue with how the linker works. There are a couple of ways to handle this:

  1. In the properties of your iOS project, add the following to 'Additional mtouch arguments' and rebuild the project: --linkskip=System.Core See Linking Xamarin.iOS Apps for more information.

  2. Instead of skipping the System.Core assembly, you can tell the linker to preserve System.Linq.Queryable. Just add this line to the AssemblyInfo.cs in your iOS project: [assembly: Preserve(typeof(System.Linq.Queryable), AllMembers = true)] Then rebuild the project.

KarthikRajaAKR commented 5 years ago

Hi @hartez,

Thank you for the solution.

Your solution can be achieved at sample level but we can not do the same in our control level. We tried with preserve attribute for Queryable extension class and Main class, but it still throws exception. Could you please check and update this?

hartez commented 5 years ago

@KarthikRajaAKR How are you applying the attribute? Can you post the code?