I have created an app using c# and winforms. I am using EF to manage a sqlite db (first time I do it in thie way). When the app is ready to deploy I use visual studio project installer 2022 to build the .exe and then I proceed to install the app.
The installation runs ok and when I start the program I can not write or read the db. This is the message I got:
System.DllNotFoundException: Unable to load DLL ‘e_sqlite3’ or one of its dependencies
I tried installing SQLitePCLRaw.bundle_e_sqlite3 (following this solution) but the error still ocurrs.
Current dependencies in my app ara these:
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="WinForms.DataVisualization" Version="1.9.2" />
</ItemGroup>
so I realize the SQLitePCLRaw.bundle_e_sqlite3 was there from the begining as a dependency of
Microsoft.EntityFrameworkCore.Sqlite
When I run the app from VS it works fine! there is no error message at all and I can write and read the db, so the issues must be located when I create the .exe.
I am targeting x86 plataform (to seccure to use in x32 and x63 bit) and these are the messages when I build the .exe
WARNING: File ‘ControlAguaPotable.exe’ of project output ‘Publish Items from ControlAguaPotable (Active)’ targeting ‘x64’ is not compatible with the project’s target platform ‘x86’
WARNING: File ‘e_sqlite3.dll’ of project output ‘Publish Items from ControlAguaPotable (Active)’ targeting ‘Unknown’ is not compatible with the project’s target platform ‘x86’
WARNING: File ‘e_sqlite3.dll’ of project output ‘Publish Items from ControlAguaPotable (Active)’ targeting ‘Unknown’ is not compatible with the project’s target platform ‘x86’
WARNING: File ‘e_sqlite3.dll’ of project output ‘Publish Items from ControlAguaPotable (Active)’ targeting ‘x64’ is not compatible with the project’s target platform ‘x86’
Packaging file ‘libe_sqlite3.so’…
Packaging file ‘libe_sqlite3.dylib’…
Packaging file ‘Microsoft.Extensions.Options.dll’…
Packaging file ‘libe_sqlite3.so’…
Packaging file ‘Newtonsoft.Json.dll’…
Packaging file ‘ControlAguaPotable.runtimeconfig.json’…
Packaging file ‘Microsoft.Extensions.Configuration.Abstractions.dll’…
Packaging file ‘libe_sqlite3.so’…
Packaging file ‘Microsoft.Extensions.DependencyInjection.Abstractions.dll’…
Packaging file ‘Microsoft.Extensions.Logging.Abstractions.dll’…
Packaging file ‘libe_sqlite3.so’…
Packaging file ‘libe_sqlite3.dylib’…
Packaging file ‘Microsoft.Extensions.DependencyModel.dll’…
Packaging file ‘libe_sqlite3.so’…
Packaging file ‘SQLitePCLRaw.core.dll’…
Packaging file ‘ControlAguaPotable.exe’…
Packaging file ‘Microsoft.Extensions.Primitives.dll’…
Packaging file ‘libe_sqlite3.dylib’…
Packaging file ‘Microsoft.Extensions.Logging.dll’…
Packaging file ‘libe_sqlite3.so’…
Packaging file ‘SQLitePCLRaw.batteries_v2.dll’…
Packaging file ‘Microsoft.EntityFrameworkCore.dll’…
Packaging file ‘e_sqlite3.dll’…
Packaging file ‘libe_sqlite3.so’…
Packaging file ‘libe_sqlite3.so’…
Packaging file ‘e_sqlite3.dll’…
Packaging file ‘Microsoft.Extensions.Caching.Abstractions.dll’…
Packaging file ‘Microsoft.EntityFrameworkCore.Sqlite.dll’…
Packaging file ‘libe_sqlite3.so’…
Packaging file ‘Microsoft.EntityFrameworkCore.Relational.dll’…
Packaging file ‘gotas1.ico’…
Packaging file ‘libe_sqlite3.so’…
Packaging file ‘Microsoft.Data.Sqlite.dll’…
Packaging file ‘e_sqlite3.dll’…
Packaging file ‘WinForms.DataVisualization.dll’…
Packaging file ‘ControlAguaPotable.dll’…
Packaging file ‘e_sqlite3.dll’…
Packaging file ‘e_sqlite3.a’…
Packaging file ‘Microsoft.Extensions.DependencyInjection.dll’…
Packaging file ‘database.db’…
Packaging file ‘libe_sqlite3.dylib’…
Packaging file ‘ControlAguaPotable.dll.config’…
Packaging file ‘WinForms.DataVisualization.Utilities.dll’…
Packaging file ‘Microsoft.Extensions.Caching.Memory.dll’…
Packaging file ‘ControlAguaPotable.pdb’…
Packaging file ‘dynamicConfig.json’…
Packaging file ‘SQLitePCLRaw.provider.e_sqlite3.dll’…
Packaging file ‘Microsoft.EntityFrameworkCore.Abstractions.dll’…
Packaging file ‘libe_sqlite3.so’…
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========
========== Rebuild completed at 03:26 p. m. and took 09.185 seconds ==========
When building I got a warning (I dont know if there could be the problem) but in the end the message says the process was completed with success.
If there is something I am doing wrong, please let me know.
Thanks in advance!