SQLitePCL.raw icon indicating copy to clipboard operation
SQLitePCL.raw copied to clipboard

e_sqlite3 library not found in Xamarin.Mac

Open nvanlaerebeke opened this issue 5 years ago • 9 comments

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 https://github.com/ericsink/SQLitePCL.raw/issues/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 https://github.com/ericsink/SQLitePCL.raw/issues/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

nvanlaerebeke avatar Aug 24 '20 09:08 nvanlaerebeke

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

ericsink avatar Aug 24 '20 14:08 ericsink

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

nvanlaerebeke avatar Aug 24 '20 14:08 nvanlaerebeke

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.

ericsink avatar Aug 24 '20 14:08 ericsink

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

nvanlaerebeke avatar Aug 24 '20 17:08 nvanlaerebeke

"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.

ericsink avatar Aug 24 '20 17:08 ericsink

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>

slakul avatar Oct 08 '20 14:10 slakul

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>

filipnavara avatar Nov 17 '20 14:11 filipnavara

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>

manijak avatar Mar 18 '21 12:03 manijak

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.

microspaze avatar Nov 23 '22 14:11 microspaze