Skip to content

Microsoft.Data.Sqlite.SqliteConnection throws a System.NullReferenceException #26816

@svetovid

Description

@svetovid

Running an application with Sqlite DB connection throws the following exception:
System.TypeInitializationException: The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.

Important! it DOES work properly for target framework net6.0-windows, and it DOES NOT work for target framework net48

Code

I don't know if it can be helpful

public SQLiteDatabase()
{
  Connection = new SQLiteConnection();
}

Stack traces

(the part which relates to Microsoft.Data.Sqlite)

System.TypeInitializationException: The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Data.Sqlite.Utilities.ApplicationDataHelper.GetFolderPath(String propertyName)
   at Microsoft.Data.Sqlite.Utilities.ApplicationDataHelper.get_LocalFolderPath()
   at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize()
   at Microsoft.Data.Sqlite.SqliteConnection..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.Data.Sqlite.SqliteConnection..ctor()

Version information

Microsoft.Data.Sqlite version: 6.0.0
Target framework: net48
Operating system: Windows 10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions