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

libe_sqlite3 2.1.0 not discovered in default location in Net Framework #494

Closed NetDwarf closed 2 years ago

NetDwarf commented 2 years ago

Hello,

I hesitated a bit to open a new issue as many issues on here sound similar, but not quite the same to mine, but maybe they are related.

Error message:

The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: e_sqlite3 assembly:<unknown assembly> type:<unknown type> member:(null)

The error happens with Microsoft.Data.Sqlite 6.0.5 which uses SQLitePCLRaw.bundle_e_sqlite3 >= 2.0.6 which means it is currently using 2.1.0.

Environment (where I could reproduce): OS: Windows 2019, Ubuntu 20.04 Arch: x64 Framework: Net 4.8 (does not happen in Net 6) Project Style: Sdk

Repro

Workaround/Hack: Manually downgrading SQLitePCLRaw.bundle_e_sqlite3 to 2.0.7 resolves the issue meaning 2.1.0 introduced the regression. More importantly moving the correct libe_sqlite3.so (probably works the same with dll in Windows) onto the same level as runtimes folder also fixes the issue. It seems that the binary is just not properly discovered.

ericsink commented 2 years ago

Nice job on this bug report.

which means it is currently using 2.1.0

Does it? When I build your repro, it resolves to 2.0.6. Anyway...

So I explicitly add:

<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.0" />

And dotnet run shows the error you described.

Then I changed:

<Platform>x64</Platform>

to:

<RuntimeIdentifier>win-x64</RuntimeIdentifier>

And it works. I believe the Platform property is an outdated way, and RuntimeIdentifier is more current.

I did this on Windows. You also mentioned Linux, but with net48, are you using Mono?

NetDwarf commented 2 years ago

Does it? When I build your repro, it resolves to 2.0.6. Anyway...

Oh, I think it did for me too. That hurts. I thought I knew, but I didn't. The issue was with 2.0.6 all along. I'm very sorry.

So I explicitly add:

<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.0" />

And dotnet run shows the error you described.

Now it gets complicated. As specifying 2.1.0 fixes the issue on my end. Anyway I get in to the corner of shame as I somehow didn't try that one. :facepalm:

ericsink commented 2 years ago

No worries. :-)