efcore: System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception.
File a bug
During the upgrade of a NuGet package, I find myself unable to run my app anymore because of this exception. I am unable to provide a working reproducable sample but I am mostly looking for guidance on what troubleshooting steps I can take to resolve this issue, since it is most probably related to the configuration.
The app in question is a Uno Platform app, and contains a subproject for processing an iOS intent.
Both the iOS and intents project are using
- Microsoft.EntityFrameworkCore 5.0.7
- Microsoft.EntityFrameworkCore.Sqlite 5.0.7
Stack traces
System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception. ---> System.Collections.Generic.KeyNotFoundException: The given key 'All' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x0001e] in <da8885cdf78b449d96de00cdb9d47225>:0
at Microsoft.EntityFrameworkCore.Query.QueryableMethods.<.cctor>g__GetMethod|185_58 (System.String name, System.Int32 genericParameterCount, System.Func`2[T,TResult] parameterGenerator, Microsoft.EntityFrameworkCore.Query.QueryableMethods+<>c__DisplayClass185_0& ) [0x00014] in <4d1f22249bbe4676a871766038953138>:0
at Microsoft.EntityFrameworkCore.Query.QueryableMethods..cctor () [0x00052] in <4d1f22249bbe4676a871766038953138>:0
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Query.Internal.QueryableMethodNormalizingExpressionVisitor.VisitMethodCall (System.Linq.Expressions.M<…>
Include provider and version information
EF Core version: 5.0.7 Database provider: Microsoft.EntityFrameworkCore.Sqlite Target framework: Not sure Operating system: MacOS Big Sur 11.4 IDE: Visual Studio for Mac 8.10.4 (build 11)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 20 (8 by maintainers)
Hi, I’ve been able to resolve this issue by telling the linker to skip the
System.Coreassembly (as the EF Core documentation says).I’ve set the Linking behavior to
SDK Onlyand added this to the Additional mtouch arguments:Until we address issue #21894, we recommend disabling the linker entirely:
We ran into this issue with Xamarin but only in iOS Release configuration. Our workaround is to specify some linking skip settings in the iOS Build properties under “Additional mtouch arguments”
–optimize=experimental-xforms-product-type --linkskip=System.Core --linkskip=mscorlib
Is there any update on this bug?
Are there any updates on this bug yet as I am currently stuck?
Since I get exactly the same error I assume the author is also using Xamarin in combination with EF Core / SQLite.
If more info is needed, I have simplified a method from my project and pasted it here. When I test it on a simulator or real device I get no errors. As soon as I load the app into the app store and test it via Testflight I get the above error.
Sounds good. I will reach out with some details.
Having same issue.
It happens when I call
DbSet<TItem>.ToList()only on iOS.I followed source code and I can not get it because it should work on both platform, Android and iOS but only Android works.
I can find a method named All in Queryable. But why reflection can not find that only in iOS?
https://github.com/dotnet/efcore/blob/59ec671ecf9bd78d7870757e909f16d100e59bc8/src/EFCore/Query/QueryableMethods.cs#L478-L483
code
queryableMethodGroups[name]throws KeyNotFoundException.https://github.com/dotnet/efcore/blob/59ec671ecf9bd78d7870757e909f16d100e59bc8/src/EFCore/Query/QueryableMethods.cs#L839-L844
dotnet/runtime System.Linq.Queryable
https://github.com/dotnet/runtime/blob/b2a5499230f005108b882ac8bd76b3868d2573e4/src/libraries/System.Linq.Queryable/src/System/Linq/Queryable.cs#L1500-L1513
Is there any workaround?
What are the previous versions of the packages you upgraded?
Something in this code isn’t working on iOS:
https://github.com/dotnet/efcore/blob/cfe1df8abdd9f3d94347d44b9bdb178510a4bb6b/src/EFCore/Query/QueryableMethods.cs#L473-L476
Possibly caused by too much of the assembly getting trimmed at runtime (see also #10963)