Bug 60421 - StringCompareTranslator' threw System.InvalidOperationException: Sequence contains no matching element in release mode without share mono runtime
Summary: StringCompareTranslator' threw System.InvalidOperationException: Sequence con...
Status: REOPENED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2017-10-27 19:20 UTC by titus.aries
Modified: 2017-12-20 01:48 UTC (History)
3 users (show)

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


Attachments
Sample repro project (2.75 MB, application/x-zip-compressed)
2017-10-27 19:20 UTC, titus.aries
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 for Bug 60421 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
REOPENED

Description titus.aries 2017-10-27 19:20:47 UTC
Created attachment 25491 [details]
Sample repro project

The issue doesn't occur on debug with/or shared runtime or in release with shared runtime.
The repro project attached.

System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.Internal.StringCompareTranslator' threw an exception. ---> System.InvalidOperationException: Sequence contains no matching element
09-01 10:15:07.768 I/MonoDroid( 2022):   at System.Linq.Enumerable.Single[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x00070] in <6a13168f1caf43ba80a2baccdd78c647>:0 
09-01 10:15:07.768 I/MonoDroid( 2022):   at Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.Internal.StringCompareTranslator..cctor () [0x0005f] in <1ce4ae811dd94fe5a5e10e630f2f4c7a>:0 
09-01 10:15:07.768 I/MonoDroid( 2022):    --- End of inner exception stack trace ---
09-01 10:15:07.768 I/MonoDroid( 2022):   at Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.RelationalCompositeExpressionFragmentTranslator..ctor () [0x00006] in <1ce4ae811dd94fe5a5e10e630f2f4
Comment 1 Eric Liu 2017-10-27 21:47:09 UTC
it's not a bug

you're shrinking EntityFrameworkCore which has a tons of reflected methods... you have to help the linker what classes and methods are used by your app/ef.

You have 2 options:

1. Skip EF / Interactive.Async / Remotion.Linq / System.Data from linking [Time wasting: O(1) ]
2. Dig yourself into EF and find what types it's trying to reach and got removed by the linker (it's a long journey) [ Time wasting: O(N), because if you change 1 query logic in your app, then you have to redefine you linkerdescription ]

(One of my app has a linkerdescription with 1K lines (!) just for EF+Relational+Sqlite+Interactive.Async+System.Data) which is ~ -1mb but a tons of time wasted
Comment 2 Jon Douglas [MSFT] 2017-10-30 02:38:59 UTC
This issue looks directly related to the linker being too aggressive with "SDK Only" linking as it cannot figure out via static analysis what is being used with reflection in these assemblies. If you were to switch to "Don't Link" your sample project will not fail with an unhanded exception because the Linker doesn't run.

Short Answer:

You will need to "linkskip" most of these assemblies.

https://developer.xamarin.com/guides/android/advanced_topics/linking/#linkskip

Long Answer:

You can create a custom linker description ruleset(https://developer.xamarin.com/guides/cross-platform/advanced/custom_linking/) for these assemblies to save on anything you don't use. To help ease that journey, you can read through my blog on the Linker Analyzer by Radek Doulik:

https://www.jon-douglas.com/2017/09/22/linker-analyzer/

This will help you identify what is being kept in your application so you can identify what is being linked out.
Comment 3 titus.aries 2017-12-19 16:07:05 UTC
No link can't be used because of the size.
This can be automated, included in the build process?