efcore: Query throws Exception with Xamarin iOS -> linking issue

When I query a DbSet e.g. with a simple ToList() call I get the exception shown below. The exception is only thrown on real iOS device. It works with the iOS emulator.

var test = context.Images.ToList();

Exception message: The type initializer for 'Microsoft.EntityFrameworkCore.Query.ResultOperators.Internal.TrackingExpressionNode' threw an exception.
Stack trace:   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.get_NodeTypeProvider () [0x0000a] in <0998bf911f014e7884d2695c95a67016>:0 
  at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler+<>c__DisplayClass15_0`1[TResult].<Execute>b__0 () [0x00000] in <0998bf911f014e7884d2695c95a67016>:0 
  at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc] (System.Object cacheKey, System.Func`1[TResult] compiler) [0x0001f] in <0998bf911f014e7884d2695c95a67016>:0 
  at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult] (System.Object cacheKey, System.Func`1[TResult] compiler) [0x00000] in <0998bf911f014e7884d2695c95a67016>:0 
  at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult] (System.Linq.Expressions.Expression query) [0x00069] in <0998bf911f014e7884d2695c95a67016>:0 
  at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult] (System.Linq.Expressions.Expression expression) [0x00000] in <0998bf911f014e7884d2695c95a67016>:0 
  at Remotion.Linq.QueryableBase`1[T].GetEnumerator () [0x0000c] in <4c6b24174f1a4a3a9c2e761b70716a02>:0 
  at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1[TEntity].System.Collections.Generic.IEnumerable<TEntity>.GetEnumerator () [0x00006] in <0998bf911f014e7884d2695c95a67016>:0 
  at System.Collections.Generic.List`1[T]..ctor (System.Collections.Generic.IEnumerable`1[T] collection) [0x00062] in <a89624c267f94034b6cf9aa0c56f8864>:0 
  at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00018] in <773264786149499a986a13db6a7d46fe>:0 
  at Erdmann.FW.LocationDatabase.DatabaseContentBuilder.Run (Erdmann.FW.LocationDatabase.LocationDbContext context) [0x00014] in E:\IRISSYS\Source\OP-Tools\Erdmann\Erdmann.FW.LocationDatabase\Erdmann.FW.LocationDatabase\DatabaseContentBuilder.cs:25 
  at Erdmann.FW.LocationDatabase.DatabaseManager.FillDatabase (Erdmann.FW.LocationDatabase.DataSources.IDataSource source) [0x0002a] in E:\IRISSYS\Source\OP-Tools\Erdmann\Erdmann.FW.LocationDatabase\Erdmann.FW.LocationDatabase\DatabaseManager.cs:64 
  at TestApp.MainViewModel.Run () [0x00049] in E:\IRISSYS\Source\OP-Tools\Erdmann\Erdmann.FW.LocationDatabase\TestApp\TestApp.Shared\MainViewModel.cs:56 

The problem seems to be the linking behavior with the Xamarin project. I’ve tried to disable linking for some assemblies in the iOS Xamarin projefct under iOS Build:

--linkskip=Microsoft.EntityFrameworkCore --linkskip=Microsoft.EntityFrameworkCore.Relational --linkskip=Microsoft.EntityFrameworkCore.Sqlite --linkskip=Remotion.Linq

That didn’t work. However disable linking completely does work (set Link Behavior to ‘Don’t Link’). But this can only be a temporary workaround not a final solution for production deployment.

Further technical details

EF Core version: v2.0.0 Database Provider: Microsoft.EntityFrameworkCore.Sqlite Operating system: Windows 10 / iOS 11.1 IDE: Visual Studio 2017 (15.4.1)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

I found an workaround (as it was blocking me to release the app), inspired by @rob2212 - use linkskip. Set Configuration to Release, Link Framework SDK only and add these in mtouch arguments:

--linkskip=Microsoft.EntityFrameworkCore --linkskip=Microsoft.EntityFrameworkCore.Relational --linkskip=Microsoft.EntityFrameworkCore.Sqlite --linkskip=Remotion.Linq --linkskip=Microsoft.Data.Sqlite.Core --linkskip=Microsoft.EntityFrameworkCore.Sqlite.Core --linkskip=Microsoft.Extensions.DependencyInjection.Abstractions --linkskip=Microsoft.Extensions.DependencyInjection --linkskip=Microsoft.Extensions.Logging.Abstractions --linkskip=Microsoft.Extensions.Logging --linkskip=Microsoft.Extensions.Caching.Abstractions --linkskip=Microsoft.Extensions.Caching.Memory --linkskip=Microsoft.Extensions.Options --linkskip=Microsoft.Extensions.Primitives --linkskip=System.Reflection --linkskip=System.Reflection.Primitives --linkskip=System.Linq --linkskip=System.Linq.Expressions --linkskip=System.Linq.Queryable

I don’t know if all are needed, but I started with EFCore dependencies and added them until it started to work.

FYI - @NPadrutt, @ajcvickers, @divega

I have the same issue, is there any solution?