I'm facing an issue where one line of code is working in debug mode but not in release mode. I have an UWP app which connects to a sqlite db in the localState folder, the line of code that does that is the one that follows
Connection = new SqliteConnection($"Data Source={ApplicationData.Current.LocalFolder.Path}\\{DB_NAME}");
I'm using the package System.Data.SQLite from SQLite Development Team, installed via NuGet, and imported as follows
using SqliteConnection = System.Data.SQLite.SQLiteConnection;
The logic is: i have a db somewhere in the pc, i have to copy the db to the localState folder (which already works), and i need to open it to start working with the data, super basic stuff. Here comes the issue: while in debug everything is working as expected, publishing the project in release mode results in the following exception on the first shared line of code
2024-08-09 11:37:58 - Value cannot be null.
Parameter name: path1 - at System.IO.Path.Combine(String, String) + 0x50
at System.Data.SQLite.SQLiteConnection..ctor(String, Boolean) + 0x34b
at Prime.Db.Database.<Inizializza>d__12.MoveNext() + 0x16f
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x21
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x70
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x38
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x17
at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0xb
at Prime.SplashScreenPage.<CaricamentoIniziale>d__8.MoveNext() + 0x3e2a
- Prime.Db.Database+<Inizializza>d__12 - <Inizializza>d__12
I'm a bit confused, as i can't figure out what's the difference between the two situations, therefore i don't know where to put the hands.
Do you guys have some hints on the case?
It would be appreciated.
Thanks in advance.
Oke,
this is a System.Data.SQLite version 1.0.118.0 (last stable build) issue.
At https://system.data.sqlite.org/index.html/doc/trunk/www/news.wiki you can find, right below the Version History section, the newer 1.0.119.0 release notes. At point number 4 is reported the following sentence
Avoid NullReferenceException from Path.Combine method when the PublishSingleFile property is enabled for a project. Pursuant to forum post 66a0d2716a
In the linked forum post more detail can be found. If you're facing the same issue you can give a quick read to the posts to see the available workarounds, i decided to downgrade to version 1.0.117.0 and everything works as expected.
That's all.