ericsink / SQLitePCL.raw

A Portable Class Library (PCL) for low-level (raw) access to SQLite
Apache License 2.0
512 stars 106 forks source link

Sqlcipher native library loading broken for .NET 6 Mac OS #473

Closed jona-1993 closed 2 years ago

jona-1993 commented 2 years ago

Hello,

I can't run my .NET 6 project for Mac. I have this error:

Termination Reason: Namespace DYLD, Code 1 Library missing Library not loaded: /libe_sqlcipher.dylib Referenced from: /Users/USER/Desktop//MedinectCoreMacOS.app/Contents/MacOS/MedinectCoreMacOS Reason: tried: '*/libe_sqlcipher.dylib' (no such file), '/usr/local/lib/libe_sqlcipher.dylib' (no such file), '/usr/lib/libe_sqlcipher.dylib' (no such file) (terminated at launch; ignore backtrace)

Application Specific Information: Library not loaded: ./bin/e_sqlcipher/mac/x86_64/libe_sqlcipher.dylib Referenced from: /Users/jona1993/Desktop/MedinectCore/MedinectCoreMacOS/bin/Debug/net6.0-macos/osx-x64/MedinectCoreMacOS.app/Contents/MacOS/MedinectCoreMacOS Reason: tried: './bin/e_sqlcipher/mac/x86_64/libe_sqlcipher.dylib' (no such file), '/usr/local/lib/libe_sqlcipher.dylib' (no such file), '/usr/lib/libe_sqlcipher.dylib' (no such file)

In my cproj:

<PackageReference Include="EFCore.BulkExtensions" Version="3.4.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="3.1.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="3.1.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.22" />
<PackageReference Include="MSBuild.Sdk.Extras" Version="3.0.44">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.0-pre20220207221914" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.0-pre20220207221914" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.0-pre20220207221914" />

libe_sqlcipher.dylib exists in:

ericsink commented 2 years ago

One problem I see is that you should never have two SQLitePCLRaw bundles. If you remove the PackageReference for bundle_green, does the problem persist?

jona-1993 commented 2 years ago

Same issue if I remove bundle_green.

ericsink commented 2 years ago

OK. I just constructed a minimal sample that works. We need to figure out how my sample is different from what you're doing.

My sample is basically just:

dotnet workload install macos dotnet new macos dotnet add package sqlitepclraw.bundle_e_sqlcipher change the version number of that PackageReference to 2.1.0-pre20220207221914 add SQLitePCL.Batteries.Init() to AppDelegate.DidFinishLaunching() (I actually took it a bit further, creating a sqlite file with a table in it, but the above would be sufficient)

Can you provide a buildable sample that demonstrates the problem and post it here as an attachment? The more minimal it is, the more helpful it is.

jona-1993 commented 2 years ago

Same issue with your test:

-------------------------------------------------------------------

You may only use the Microsoft .NET Core Debugger (vsdbg) with

Visual Studio Code, Visual Studio or Visual Studio for Mac software

to help you develop and test your applications.

-------------------------------------------------------------------

dyld[8657]: Library not loaded: ./bin/e_sqlcipher/mac/x86_64/libe_sqlcipher.dylib

  Referenced from: /Users/jona1993/Desktop/testMACNET6/bin/Debug/net6.0-macos/osx-x64/testMACNET6.app/Contents/MacOS/testMACNET6

  Reason: tried: './bin/e_sqlcipher/mac/x86_64/libe_sqlcipher.dylib' (no such file), '/usr/local/lib/libe_sqlcipher.dylib' (no such file), '/usr/lib/libe_sqlcipher.dylib' (no such file)

The program '[8657] testMACNET6' has exited with code 1 (0x1).

The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.

testMACNET6.zip

I tested that with Visual studio 2022 preview for MAC and Rider EAP

Visual studio information:

.NET SDK (x64)
SDK: /usr/local/share/dotnet/sdk/6.0.200/Sdks
SDK Versions:
    6.0.200
    6.0.102
    6.0.101
    6.0.100
    6.0.100-rc.1.21463.6
    6.0.100-preview.7.21379.14
    5.0.405
    5.0.404
    5.0.403
    5.0.402
    5.0.401
    5.0.400
    5.0.302
    5.0.301
    5.0.203
    5.0.202
    5.0.103
    5.0.102
    5.0.101
    5.0.100
    5.0.100-rc.2.20479.15
    5.0.100-preview.5.20279.10
    3.1.416
    3.1.415
    3.1.414
    3.1.413
    3.1.412
    3.1.411
    3.1.410
    3.1.409
    3.1.408
    3.1.406
    3.1.405
    3.1.404
    3.1.403
    3.1.402
    3.1.401
    3.1.300
    3.1.200
    3.1.102
    3.1.100
    3.1.100-preview3-014645
    3.1.100-preview2-014569
    3.0.100
    2.1.810
MSBuild SDKs: /usr/local/share/dotnet/sdk/6.0.200/Sdks

Xamarin.Mac
Version: 8.6.0.3 (Visual Studio Community)
Hash: caa899d24
Branch: d17-1
Build date: 2022-01-16 21:16:56-0500

EDIT: Same issue with 2.0.7. It's maybe a breaking change with a new version of visual studio 2022 mac.

ericsink commented 2 years ago

@jona-1993 I tried your test project and it works for me.

More specifically, I downloaded your test project, unzipped it, removed the bin and obj directories, and typed dotnet run. I am not using Visual Studio or Rider.

I am curious if this works for you from the command line instead of the IDE.

jona-1993 commented 2 years ago

No, it doesn't works. I tested: dotnet clean dotnet build dotnet run

Same error..

jona-1993 commented 2 years ago

It works now. I don't now how I fixed that.. An update maybe?