Skip to content
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

Can't use Entity Framework Core in iOS Release builds #12537

Closed
Glorfindel83 opened this issue Jan 10, 2023 · 5 comments
Closed

Can't use Entity Framework Core in iOS Release builds #12537

Glorfindel83 opened this issue Jan 10, 2023 · 5 comments
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) external partner/macios Issues for the Mac / iOS SDK partner Issue or Request from a partner team platform/iOS 🍎 s/needs-info Issue needs more info from the author t/bug Something isn't working

Comments

@Glorfindel83
Copy link

Glorfindel83 commented Jan 10, 2023

Description

When running a Release build of an iOS app with Entity Framework Core, the app crashes upon startup. Debug builds and Android builds (Debug and Release) work fine. It has something to do with AOT compilation which is required by Apple; somehow it trims away relevant parts of the library. See also this Stack Overflow question.

Steps to Reproduce

The easiest way to reproduce it on macOS is to use the .NET MAUI App template in Visual Studio, edit the project file and add some configuration to make sure you can use dotnet build (Release builds from Visual Studio for Mac don't work at the moment):

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-ios|AnyCPU'">
	  <CreatePackage>false</CreatePackage>
	  <CodesignProvision>Automatic</CodesignProvision>
	  <CodesignKey>iPhone Developer</CodesignKey>
	  <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
	</PropertyGroup>
	<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-ios|AnyCPU'">
	  <CreatePackage>false</CreatePackage>
	  <CodesignProvision>Automatic</CodesignProvision>
	  <CodesignKey>iPhone Distribution</CodesignKey>
	  <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
	</PropertyGroup>

Open the project folder in Terminal, and run

dotnet build MauiEFCore.csproj -c Release -f net6.0-ios -t:Run -p:_DeviceName=<Device UDID>

(be sure to specify the right project file, and the UDID of your iPhone). This works, but as soon as you add Entity Framework Core to the project:

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.11" />
    <PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.3" />
  </ItemGroup>

the app starts to crash on startup.

Version with bug

7.0 (current)

Last version that worked well

Xamarin Forms 5

Affected platforms

iOS

Affected platform versions

iOS 16

Did you find any workaround?

No

Relevant log output

Launched application 'com.companyname.mauiefcore' on 'Gerwin's iPhone 11' with pid 25752
2023-01-06 16:00:53.767 MauiEFCore[25752:10999573] error: Failed to load AOT module 'Microsoft.Maui.Graphics' while running in aot-only mode because a dependency cannot be found or it is out of date.

=================================================================
    Native Crash Reporting
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
    Native stacktrace:
=================================================================
    0x104228540 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x104211788 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x104227d28 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x1f2ed0a90 - /usr/lib/system/libsystem_platform.dylib : <redacted>
    0x1f2f6c1ac - /usr/lib/system/libsystem_pthread.dylib : pthread_kill
    0x1ac554c8c - /usr/lib/system/libsystem_c.dylib : abort
    0x103f6d5d4 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : xamarin_find_protocol_wrapper_type
    0x104264d10 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x104264e44 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x104200664 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x1040c9ea8 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x1040c9900 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x1040cb5bc - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x103f6cbf8 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : xamarin_get_block_descriptor
    0x10426cb64 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x103f7685c - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : xamarin_log
    0x10426cd04 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x1c3776960 - /usr/lib/dyld : <redacted>

=================================================================
    Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x1e284f160):0x1e284f150  ff 0f 5f d6 c0 03 5f d6 10 29 80 d2 01 10 00 d4  .._..._..)......
0x1e284f160  03 01 00 54 7f 23 03 d5 fd 7b bf a9 fd 03 00 91  ...T.#...{......
0x1e284f170  8e ed ff 97 bf 03 00 91 fd 7b c1 a8 ff 0f 5f d6  .........{...._.
0x1e284f180  c0 03 5f d6 7f 23 03 d5 fd 7b bf a9 fd 03 00 91  .._..#...{......

=================================================================
    Managed Stacktrace:
=================================================================
=================================================================
  Application 'com.companyname.mauiefcore' terminated (with exit code '' and/or crashing signal '6).

Build succeeded.
@Glorfindel83 Glorfindel83 added the t/bug Something isn't working label Jan 10, 2023
@Eilon
Copy link
Member

Eilon commented Jan 10, 2023

@ajcvickers @bricelam - do you have any tips on how to investigate what can cause this and how to work around?

@Eilon Eilon added the area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) label Jan 10, 2023
@ajcvickers
Copy link
Member

@Eilon Not really. If the app is using trimming, then it could well be a problem with that. @roji might know more. Beyond that, EF uses dynamic code generation, so it needs the expression interpreter to be enabled. If it's neither of those things, then it's likely a bug somewhere in platform code, but I have no idea how to track that down.

@Ghevi
Copy link

Ghevi commented Jan 11, 2023

I've successfully published an app on the AppStore that uses EF core with sqlite.
You have to add this line for iOS.

 <UseInterpreter>True</UseInterpreter>

Also delete bin and obj before publishing otherwise there will be a runtime exception the first time you query the db.
See 9176, hope it helps.

@jsuarezruiz jsuarezruiz added the s/needs-info Issue needs more info from the author label Jan 11, 2023
@ghost
Copy link

ghost commented Jan 11, 2023

Hi @Glorfindel83. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@mattleibow
Copy link
Member

mattleibow commented Jan 11, 2023

This issue was moved to xamarin/xamarin-macios#17194

@dotnet dotnet locked and limited conversation to collaborators Jan 11, 2023
@samhouts samhouts added partner Issue or Request from a partner team partner/macios Issues for the Mac / iOS SDK external labels May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) external partner/macios Issues for the Mac / iOS SDK partner Issue or Request from a partner team platform/iOS 🍎 s/needs-info Issue needs more info from the author t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants