Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nullables in Entity Framework Core on Xamarin iOS

We are developing an Mobile app using Xamarin.Forms, which is backed by a Web app using ASP.NET Core. We load various models from databases on both the Web and Mobile apps, and recently we have transitioned to using EntityFramework Core (will refer to as EFCore) on the Web app.

We are currently looking at transitioning the Mobile app to also use the EFCore to allow us to share more code between the apps, but have run into problems with EFCore on iOS. It seems able to compile and run, and can load simple models, but fails to load nullable types which are used to specify optional relationships between models. This person seems to have EFCore running in iOS and provides a project for their code. I have pulled and ran the project myself to check it works, which it did, but after adding a nullable relation to his simple model, it subsequently failed to both load and create an item with this error:

System.ExecutionEngineException: Attempting to JIT compile method '(wrapper runtime-invoke) :runtime_invoke_void__this___int_byte_byte_byte_byte_byte_object_object_object_object_object_object_object_object_object_object_Nullable1 (object,intptr,intptr,intptr)' while running in aot-only mode. See https://developer.xamarin.com/guides/ios/advanced_topics/limitations/ for more information.

This error does not occur when running on the simulator, only on a device.

My question is whether anyone has had any success with getting Nullables working with EFCore on Xamarin iOS?

Many thanks, Will.

P.S. We are open to changing EFCore/Xamarin.iOS/Mono version to solve the problem.

like image 963
William Gilmour Avatar asked Aug 09 '17 13:08

William Gilmour


People also ask

What's new in Xamarin iOS 9?

Xamarin.iOS 9.0 adds support for consuming these embedded frameworks (created with Xcode) in Xamarin.iOS apps. It will not be possible to create embedded frameworks from any type of Xamarin.iOS projects, only consume existing native (Objective-C) frameworks.

How do I create Xamarin forms apps with EF Core?

To create Xamarin.Forms apps with EF Core, you install the package for the EF Core database provider (s) you want to target into all of the projects in the Xamarin.Forms solution. This tutorial uses the SQLite provider. The following NuGet package is needed in each of the projects in the Xamarin.Forms solution.

Is it possible to create embedded frameworks in Xamarin iOS?

It will not be possible to create embedded frameworks from any type of Xamarin.iOS projects, only consume existing native (Objective-C) frameworks. There are two ways to consume frameworks in Xamarin.iOS: This has to be set for each project configuration. This will work for all configurations.

What is Mono runtime in Xamarin iOS?

The Mono runtime Internally Xamarin.iOS takes advantage of this feature to link with the Mono runtime as a framework, instead of linking the Mono runtime statically into each extension and the container app. This is automatically done if the container app is a Unified app, it contains extensions and the target deployment is iOS 8.0 or higher.


1 Answers

This is a known issue. iOS has some limitations on generics, nullables... because Apple disallow code generation at runtime.

The issue is referenced on github for entity framework : Xamarin iOS : Crash when i add row to table with nullable type or with a lot of columns

And on Xamarin's bugzilla : Bug 58424 - Xamarin iOS : EF Core crash when I add row to table with nullable type or with a lot of columns

like image 197
Guillaume Avatar answered Sep 28 '22 09:09

Guillaume