Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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
In special cases on GitHub you might also want the comments:
GitHub Markdown with public comments
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
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
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.
You will need to "linkskip" most of these assemblies.
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:
This will help you identify what is being kept in your application so you can identify what is being linked out.
No link can't be used because of the size.
This can be automated, included in the build process?