MAUI EF Core 6 crash on IOS

Sergey 25 Reputation points
2023-04-21T09:28:45.7133333+00:00

Getting immediate crash during saving data into sqlite. using following release parameters

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-ios|AnyCPU'">
    <MtouchProfiling>True</MtouchProfiling>
    <MtouchExtraArgs>--interpreter</MtouchExtraArgs>
    <UseInterpreter>True</UseInterpreter>
  </PropertyGroup>

used packages

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.16" />    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.16" />    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.16">      <PrivateAssets>all</PrivateAssets>      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>    </PackageReference>

at this stage using prepopulated database which copied following way

var assembly = IntrospectionExtensions.GetTypeInfo(typeof(App)).Assembly;
var names = assembly.GetManifestResourceNames();
using (Stream stream = assembly.GetManifestResourceStream("TestProject.Test.db")) {
    using (MemoryStream memoryStream = new MemoryStream()) {
        stream.CopyTo(memoryStream);

        var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Test.db");

        File.WriteAllBytes(path, memoryStream.ToArray());
    }
}

Data from db retrieved successfully. Save works on Windows and Android.

Developer technologies | .NET | Entity Framework Core
Developer technologies | .NET | .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2023-04-21T11:46:14.2266667+00:00

    Hello,

    As you said, it's related to the folder path.

    var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Test.db");
    

    Please try App data directory (string mainDir = FileSystem.Current.AppDataDirectory;) and refer to
    File system helpers - .NET MAUI | Microsoft Learn.

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.