Skip to content

M.D.Sqlite: More robust cross-platform extension loading #35715

Description

@roji

Our current (native) extension loading story for Sqlite isn't great: it's usually up to the user to make sure that the native DLL/so/dylib is present in the operating system search path, etc. (e.g. spatialite docs). This notably makes the getting started story for popular extensions like sqlite_vec much more difficult than it should be.

Thanks to @krwq for working on improving this.

Note: update the spatialite docs.

Activity

  1. added this to the 10.0.0 milestone on Mar 3, 2025
  2. removed this from the 10.0.0 milestone on Mar 3, 2025
  3. roji commented on Mar 3, 2025

    @roji
    MemberAuthor

    Keeping open to track backporting to 8.0 and 9.0, for a better sqlite_vec story.

  4. changed the title [-]M.D.Sqlite: more robust cross-platform extension loading[/-] [+]M.D.Sqlite: More robust cross-platform extension loading[/+] on Mar 3, 2025
  5. added this to the 8.0.x milestone on Mar 4, 2025
  6. added theissue type on Jun 15, 2025
  7. Zetanova commented on Oct 20, 2025

    @Zetanova

    The SpatialiteLoader class has static string mod_spatialite but the LoadExtension class fully supports also absolute paths.
    The EF core more or less forces a call SQLitePCL.Batteries.Init() but it is sometimes not wanted, especially if an open sqlite connection used for the DBContextOptions.

    There is a very nasty behavior with the none standard module loading of sqlite extension like of spatialite
    and it seams there is no guard against dual loading of two versions of libsqlite3 native and also libe_sqlite3 by mistake.

    with only native libsqlite3 or libe_sqlite3 it is easy but to have both in a project for cross platform use
    the SQLitePCL.Batteries.Init() call will take always libe_sqlite3if the depdency is added
    and even if the native module was already used.

    This results in a very unstable and none-deterministic crashes (2/3 simple runs will work).

    See my working example to overcome this issue and use a project with docker and also on windows:
    dotnet/EntityFramework.Docs#5308 (comment)

  8. roji commented on Oct 20, 2025

    @roji
    MemberAuthor

    @Zetanova is your comment specifically related to work in #35617 (the PR for this issue)? In any case, is this the issue already being tracked in dotnet/EntityFramework.Docs#5308, or are you reporting an additional problem?

  9. Zetanova commented on Oct 20, 2025

    @Zetanova

    @roji yes the issue is tracked there, but it is related to cross-platform.
    Currently if only one of the packages is used (SQLitePCLRaw.bundle_e_sqlite3 or SQLitePCLRaw.bundle_sqlite3)
    then it works great and it will be locked more or less to one platform.

    If both are used in a project, then it will generate sometimes hard errors
    because of the internal setup in EF core of the sqlite connections.
    It took me long time to discover that EF core tries to load also the e_sqlite3 bundle over the already loaded libsqlite3,
    even if the sqlite connection was manually setup and all modules loaded and initialized.

    Errors could be under docker/ubuntu:24.04, and more often then not it works without any errors:
    corrupted size vs. prev_size
    malloc(): unaligned tcache chunk detected
    AddGeometryColumn() error: unexpected metadata layout
    munmap_chunk(): invalid pointer

  10. roji commented on Oct 20, 2025

    @roji
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions