AOT Compilation Error with System.Data.SQLite.EF6.dll in .NET Maui Blazor Hybrid App

240 views Asked by At

I am developing a .NET Maui Blzor app that uses SQLite, and I've run into an issue during the build process in release mode. The specific error message is related to AOT (Ahead of Time) compilation. Here's the error message:

Precompiling failed for \obj\Release\net7.0-android\android-x86\linked\System.Data.SQLite.EF6.dll with exit code 1. Mono Ahead of Time compiler - compiling assembly \obj\Release\net7.0-android\android-x86\linked\System.Data.SQLite.EF6.dll Using profile data file 'C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\7.0.86\Sdk\maui.aotprofile' Using profile data file 'C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\7.0.86\Sdk\maui-blazor.aotprofile' Failed to load method 0x600015b from '\obj\Release\net7.0-android\android-x86\linked\System.Data.SQLite.EF6.dll' due to Could not load file or assembly 'System.Data.SQLite, Version=1.0.117.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies.. Run with MONO_LOG_LEVEL=debug for more information. AOT of image obj\Release\net7.0-android\android-x86\linked\System.Data.SQLite.EF6.dll failed.

I've tried several solutions like ensuring all required assemblies are present, cleaning, and rebuilding the solution, but the issue persists.

When I disable AOT for the whole solution, everything builds fine. However, I want to understand if this issue can be resolved while leaving AOT enabled as it has performance benefits. Moreover, I tried to disable AOT for just the DB project using <EnableAOT>false</EnableAOT> in the project's .csproj file, but it didn't help.

Has anyone else faced a similar issue? Is there a way to disable AOT for just a single project? Or any other suggestions on how to resolve this error with AOT enabled? Any help would be much appreciated!

1

There are 1 answers

0
Baz On

I have found the root cause of the issue. The problem was due to my usage of Microsoft.EntityFrameworkCore from the System.Data.SQLite.EF6 package library.

The correct approach is to use Microsoft.EntityFrameworkCore from the Microsoft.EntityFrameworkCore.Sqlite.dll package.

After switching to the Microsoft.EntityFrameworkCore.Sqlite and deleting System.Data.SQLite, System.Data.SQLite.EF6, the AOT compilation error disappeared and the build process completed successfully in release mode with AOT enabled.

I hope this update helps anyone who might encounter a similar issue in the future.