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

e_sqlite3 library not found in Xamarin.Mac #358

Open
nvanlaerebeke opened this issue Aug 24, 2020 · 9 comments
Open

e_sqlite3 library not found in Xamarin.Mac #358

nvanlaerebeke opened this issue Aug 24, 2020 · 9 comments

Comments

@nvanlaerebeke
Copy link

Been trying to get EFCore with SQLite working when using Xamarin.Mac.
At runtime it cannot load the e_sqlite3 library.

When switching to Xamarin.Modern everything works right away (but is not an option).

First thought it had to do with #343, but tried those work arounds and have had no luck.

I've got a sample demonstrating the issue with all the info I could gather here:
https://github.com/nvanlaerebeke/EFCore_XamarinMac

In the sample above I made sure to use:

SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3()); 
SQLitePCL.raw.FreezeProvider();

And only reference Microsoft.Data.Sqlite.Core with SQLitePCLRaw.core, SQLitePCLRaw.lib.e_sqlite3 and SQLitePCLRaw.provider.e_sqlite3 as mentioned in #343

Don't think I missed any:
https://github.com/nvanlaerebeke/EFCore_XamarinMac/blob/master/XamarinMac_EFCore/packages.config

Any idea how to get it to work?
Think this is an issue with Xamarin.Mac specifically as it works fine using Xamarin.Modern

@ericsink
Copy link
Owner

This is a known problem, although, strangely, there appears to be no issue for it.

It was mentioned in the 2.0 release notes:

https://github.com/ericsink/SQLitePCL.raw/blob/master/v2.md

@nvanlaerebeke
Copy link
Author

I'm guessing there is no workaround?, I'll try to switch to Xamarin.Modern and convert all the projects to .net standard

@ericsink
Copy link
Owner

Actually I'm quite sure there IS a workaround, I just don't remember how to do it. :-)

The problem is conceptually rather simple -- we just need the e_sqlite3 library to end up where the Mac code can find it. Once that happens, everywhere works.

I'll take a closer look again and see if I can figure something out.

@nvanlaerebeke
Copy link
Author

Would be much appreciated, can't imagine I'm the only one using Xamarin.Mac :)

@ericsink
Copy link
Owner

"can't imagine I'm the only one using Xamarin.Mac"

Probably not, but it's close. :-) I've been surprised how few people have mentioned this problem.

@slakul
Copy link

slakul commented Oct 8, 2020

I had similar problem with compilation in 'Release' and used following workaround. I added it into the project file:

<ItemGroup Condition=" '$(Configuration)' == 'Release'">
    <NativeReference Include="/Users/runner/.nuget/packages/sqlitepclraw.lib.e_sqlite3/2.0.3/runtimes/osx-x64/native/libe_sqlite3.dylib">
      <Kind>Dynamic</Kind>
      <SmartLink>False</SmartLink>
    </NativeReference>
  </ItemGroup>

@filipnavara
Copy link
Contributor

The following workaround worked for us:

  <ItemGroup>
    <PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="2.0.4" PrivateAssets="None" GeneratePathProperty="true" />
    <NativeReference Include="$(PkgSQLitePCLRaw_lib_e_sqlite3)/runtimes/osx-x64/native/libe_sqlite3.dylib">
      <Kind>Dynamic</Kind>
      <SmartLink>False</SmartLink>
    </NativeReference>
  </ItemGroup>

@manijak
Copy link

manijak commented Mar 18, 2021

The only way I could get this to work on my end is by copying the libe_sqlite3.dylib to my Xamarin.Mac projects Resources folder and then adding it as a native reference from there.

<ItemGroup>
    <BundleResource Include="Resources\libe_sqlite3.dylib" />
  </ItemGroup>
  <ItemGroup>
    <NativeReference Include="Resources\libe_sqlite3.dylib">
      <Kind>Dynamic</Kind>
      <SmartLink>False</SmartLink>
    </NativeReference>
  </ItemGroup>

@microspaze
Copy link

microspaze commented Nov 23, 2022

You just need add the base sqlite3 lib:

<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="2.1.2" />
<PackageReference Include="SQLitePCLRaw.lib.e_sqlcipher" Version="2.1.2" />

It can fix the DllNotFoundException error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants