-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[entityframeworkcore] Query throws Exception with Xamarin iOS when linking #3394
Comments
From @ajcvickers on November 6, 2017 20:40 @rob2212 Would it be possible for you to post a code listing or project that reproduces what you are seeing? It looks like this is likely a Xamarin issue, but we would like to investigate before potentially filing an issue with them. |
From @rob2212 on November 7, 2017 6:6 I will prepare sample project for reproduction later on. |
From @rob2212 on November 8, 2017 8:56 @ajcvickers I've created a test project which you can use to reproduce the issue. I've inserted some warnings at the relevant places. Where can I upload it? Attachments here can only be 10 MB. |
From @ajcvickers on November 8, 2017 16:52 @rob2212 Two things to try:
|
From @rob2212 on November 9, 2017 11:8 |
From @eusebiu on November 13, 2017 20:37 Any news on this? Thanks! |
From @NPadrutt on November 14, 2017 10:48 I have the same issue with the extension ToListAsync(). |
From @eusebiu on November 16, 2017 19:4 After updating to 2.0.1 and call .Any(), I get: The type initializer for 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions' threw an exception |
From @Deepakroy on November 22, 2017 9:50 I have the same issue, is there any solution? |
From @eusebiu on November 22, 2017 11:5 I found an workaround (as it was blocking me to release the app), inspired by @rob2212 - use linkskip.
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 |
From @evertonutfpr on January 18, 2018 17:5 Any news on this? Thanks! |
From @shanhongyue on February 4, 2018 9:26 I did not encounter this problem in the iPhone X simulator, but encountered in my real iPhone X machine, which was very interesting. |
Tried various options mentioned above with linkskip still no luck finally ended up converting datatype datetime? to string also double? To string then everything worked. |
EntityFrameworkCore uses quite a bit of reflection which has a few drawbacks: performance (it's slower) and hiding code usage from static analysis tools. The later is the reason why, when the linker is enabled (default for device builds), you run into issues at runtime. The linker cannot see everything that's required, because there's no hints from the library to help it, so code used only thru reflection is removed. The attached sample works for me when when I add this line:
to the Now this is not optimal (but better than all the Note that there might be other places where reflection is used on BCL types so YMMV for your full application. This is a workaround for consumers of the EntityFrameworkCore. The right fix would be for EntityFrameworkCore to provide all the required hints to the linker (as part of the assembly) since the library authors are the best placed to know the reflection usage made by their code. |
Hey, I get it working by create a file in my iOS project : Linkers.xml, and add this inside :
Don't forget to change the build action for this file by right clicking on it => Build action => Linker description. Here is my complete file that take care of EF Core :
Hope that can help someone :) |
Thanks to all of you guys for listing the workarounds. For me, the only thing that worked was adding the following line at the beginning of my Main.cs:
No additional mtouch arguments needed to be set. In fact, I tried adding
but there was no hope! Note that I have set my linker behavior to "Link framework SDKs only" as well. By the way, I was getting "Sequence contains no matching element" exception on the physical device when calling Thank you so much @spouliot |
@AmirMahdiNassiri In any case the use of the attribute is much easier as you found out :) |
@spouliot Oh I see. Thank you so much for sharing your knowledge :) |
@spouliot - Is this issue still actually being looked at by the Xamarin team? It is now more than two years later and this issue still exists even with the current releases of Xamarin and EFCore. It seems like this issue should be addressed by the Xamarin team properly, rather than just leaving it to developers to run into obscure problems with EFCore when running on physical iOS devices and then wasting a heap of time trying to figure out what is going on and then eventually stumbling across this post. Am i missing something and this is really not as big an issue as it seems to be to me? I would have thought the majority of people using EFCore would be using Linq as well. |
Try with @Lapinou42 its worked for me |
Thanks, yeah that was the option that I ended up using successfully. My post was more about why this is even still necessary 2 years later and if anything is planned to resolve it to save other developers the hassles associated with this issue in the future. |
As of 2021: This error still exists in exactly the same way. Is there a disadvantage if I omit the linking? |
From @rob2212 on November 2, 2017 16:29
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();
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)
Copied from original issue: dotnet/efcore#10207
The text was updated successfully, but these errors were encountered: