Exception: Library e_sqlite3 not found (again)
I notice some discussion around the topic to use the library against net47 or net48 target framework, the project works fine in net7 or net8.
The project references are: PackageReference Include="Microsoft.Data.Sqlite.Core" Version="8.0.0-preview.6.23329.4" PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.5"
The code is:
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
SQLitePCL.Batteries_V2.Init();
using var dbConnection = new SqliteConnection();
}
result:
Exception: Library e_sqlite3 not found
plat: win
suffix: DLL
possibilities (2):
1) C:\Users\rodrigov\source\repos\SqliteTest\SqliteTest\bin\Debug\net48\runtimes\win-x64\native\e_sqlite3.dll
2) C:\Users\rodrigov\source\repos\SqliteTest\SqliteTest\bin\Debug\net48\e_sqlite3.dll
win TryLoad: C:\Users\rodrigov\source\repos\SqliteTest\SqliteTest\bin\Debug\net48\runtimes\win-x64\native\e_sqlite3.dll
thrown: System.ComponentModel.Win32Exception (0x80004005): The specified module could not be found
at SQLitePCL.NativeLibrary.TryLoad(String name, Loader plat, Action1 log, IntPtr& h) win TryLoad: C:\Users\rodrigov\source\repos\SqliteTest\SqliteTest\bin\Debug\net48\e_sqlite3.dll thrown: System.ComponentModel.Win32Exception (0x80004005): %1 is not a valid Win32 application at SQLitePCL.NativeLibrary.TryLoad(String name, Loader plat, Action1 log, IntPtr& h)
NOT FOUND
This was test on Windows 11.
What version of SQLitePCLRaw are you using?
Which nuget package?
And what other nuget package? Since SqliteConnection is not in the SQLitePCLRaw API.
And your code snippet got mangled. Can you fix it? Or at least clarify that the Init() call is prior to the SqliteConnection usage?
Perhaps try adding
<RuntimeIdentifer>win-x64</RuntimeIdentifier>
to your csproj for the net48 target, to see if that makes a difference.
Sorry, i should have pay attention to the original comment I edited. calling -> SQLitePCL.Batteries_V2.Init(); make it fails. If you comment that line you will notice that the new SqliteConnection() will fail too
Does the RuntimeIdentifier suggestion make a difference?
Eric, Yes i tried and it seems to work. But i'm afraid is not a great solution for my case where i want my project to run on the main 3 platforms Windows/Linux/MacoS. Wondering what is the root cause on the underlying code that attempt to load the native dll. Are you suggesting that i add runtime ids for all platforms ?
Are you suggesting that i add runtime ids for all platforms ?
No.
Mostly I was just trying to confirm what was going wrong.
But now that we know...
It's my understanding that when targeting .NET Framework, setting a RuntimeIdentifier is Microsoft's recommendation nowadays.
If you're targeting multiple frameworks, you could set the RID for only net48 by using a PropertyGroup with a condition.