Objective: Retrieve a Base object from a local SQL database
Issue: Operations.Receive(…) throws a ArgumentNullException even though the object ID is present in the database.
Hi,
I am trying to retrieve some Speckle objects from a local SQL database using the C# API. When running Operations.Receive(…) with an ID that I know is in the database, I get the following error:
2023-07-21 17:14:23.3211|INFO|Attempting to fetch commit '286e2d8a577eed6c089705104498dc54'...
2023-07-21 17:14:24.1959|ERROR|System.ArgumentNullException: Value cannot be null.
at System.Threading.Monitor.Enter(Object obj)
at Speckle.Core.Transports.SQLiteTransport.GetObject(String hash)
at Speckle.Core.Api.Operations.<Receive>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at ...Program.<>c__DisplayClass3_0.<<Main>b__0>d.MoveNext() in ...Program.cs:line 119
The relevant lines that are throwing the error are:
var transport = new Speckle.Core.Transports.SQLiteTransport(projectDir, modelDir, dbName);
resObj= Task.Run(async () => await Speckle.Core.Api.Operations.Receive(lastCommit, null, transport, disposeTransports: true)).Result;
I have verified that the hash 286e2d8a577eed6c089705104498dc54 is, in fact, in the database using a database browser.
The console app is built for .NET Framework 4.8, Visual Studio 2022, Windows x64.
I think your SQLite transport is failing find/connect to the db. Which then leaves the transport in an invalid state when the call to GetObjects is made by Operations.Receive.
Unfortunately, the 2.14 version of our SQLite transport appears to just swallow the exception, giving you the caller no information about what failed.
You might be able to set your IDE to break on any CLR exception, to intercept the exception message.
If not, I’m just making a pr for our upcoming 2.15 release; a small change that will make the SQLite transport throw, with info about what went wrong.
This change should be included in our 2.15 release we plan on making Monday.
Your transport will still fail, but at least you will get the error message for why it fails. And then hopefully you’re able to fix the rest (if not, let me know and I can help investigate further)
Looking at the log, I do get this exception before that:
[10:37:40 WRN] Cannot set user id for the global log context.
System.TypeInitializationException: 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.Exception: Library e_sqlite3 not found
plat: win
suffix: DLL
possibilities (2):
1) ...\bin\x64\Debug\runtimes\win-x64\native\e_sqlite3.dll
2) ...\bin\x64\Debug\e_sqlite3.dll
win TryLoad:...\bin\x64\Debug\runtimes\win-x64\native\e_sqlite3.dll
thrown: System.ComponentModel.Win32Exception (0x80004005): Det angivne modul blev ikke fundet
at SQLitePCL.NativeLibrary.TryLoad(String name, Loader plat, Action`1 log, IntPtr& h)
win TryLoad: ...\bin\x64\Debug\e_sqlite3.dll
thrown: System.ComponentModel.Win32Exception (0x80004005): Det angivne modul blev ikke fundet
at SQLitePCL.NativeLibrary.TryLoad(String name, Loader plat, Action`1 log, IntPtr& h)
NOT FOUND