# 'System.NullReferenceException' occurred in SQLitePCLRaw.core.dll

**URL:** <https://discuss.zetetic.net/t/system-nullreferenceexception-occurred-in-sqlitepclraw-core-dll/4943>\
**Category:** Issues\
**Created:** [May 5, 2021, 10:43pm UTC](https://discuss.zetetic.net/t/system-nullreferenceexception-occurred-in-sqlitepclraw-core-dll/4943 "2021-05-05T22:43:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashiva](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@ashiva](https://discuss.zetetic.net/u/ashiva)\
**Post date:** [May 5, 2021, 10:43pm UTC](https://discuss.zetetic.net/t/system-nullreferenceexception-occurred-in-sqlitepclraw-core-dll/4943/1 "2021-05-05T22:43:12Z")

</div>

Running into this error intermittently.

* * *

System.NullReferenceException  
HResult=0x80004003  
Message=Object reference not set to an instance of an object.  
Source=SQLitePCLRaw.core  
StackTrace:  
at SQLitePCL.raw.sqlite3\_finalize(sqlite3\_stmt stmt)  
at SQLitePCL.sqlite3\_stmt.Finalize()

* * *

Above exception is preceded by this

* * *

## SOURCE: SQLitePCLRaw.provider.sqlcipher

STACK TRACE:  
at SQLitePCL.SQLite3Provider\_sqlcipher.NativeMethods.sqlite3\_prepare\_v2(IntPtr db, IntPtr pSql, Int32 nBytes, IntPtr& stmt, IntPtr& ptrRemain)  
at SQLitePCL.SQLite3Provider\_sqlcipher.SQLitePCL.ISQLite3Provider.sqlite3\_prepare\_v2(IntPtr db, String sql, IntPtr& stm, String& remain)  
at SQLitePCL.raw.sqlite3\_prepare\_v2(sqlite3 db, String sql, sqlite3\_stmt& stmt, String& tail)  
at SQLite.SQLite3.Prepare2(sqlite3 db, String query)  
at SQLite.SQLiteCommand.Prepare()  
at SQLite.SQLiteCommand.ExecuteNonQuery()  
at SQLite.SQLiteConnection.Execute(String query, Object args)  
at SQLite.SQLiteConnection.SetKey(String key)  
at SQLite.SQLiteConnection..ctor(SQLiteConnectionString connectionString)

* * *

I am using sqlite-net-sqlcipher v1.6.292 on .NET Framework 4.5.1.

Code is straightforward:

var options = new SQLiteConnectionString(dbPath, true, key: keyValue);  
var connection = new SQLiteConnection(options); // Exception mentioned above gets thrown here

Any input is appreciated. Thanks.
