Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling SqliteConnection from Microsoft.Data.Sqlite v6.0.0 throws TypeInitializationException #26729

Closed
faburaya opened this issue Nov 17, 2021 · 5 comments

Comments

@faburaya
Copy link

faburaya commented Nov 17, 2021

I have just upgraded the nuget package Microsoft.Data.Sqlite to version 6.0.0 and this code

        public IDbConnection OpenOrCreateDatabase(string databaseFilePath)
        {
            string connectionString = new SqliteConnectionStringBuilder()
            {
                Mode = SqliteOpenMode.ReadWriteCreate,
                Cache = SqliteCacheMode.Shared,
                DataSource = databaseFilePath
            }.ToString();

            return new SqliteConnection(connectionString);
        }

now fails with the exception reported below

[xUnit.net 00:00:01.41]       System.TypeInitializationException : The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
[xUnit.net 00:00:01.41]       ---- System.NullReferenceException : Object reference not set to an instance of an object.
[xUnit.net 00:00:01.41]       Stack Trace:
[xUnit.net 00:00:01.41]            at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
[xUnit.net 00:00:01.41]         D:\a\1\s\Reusable.DataAccess.Sqlite\SqliteDatabaseCreationHelper.cs(56,0): at Reusable.DataAccess.Sqlite.SqliteDatabaseCreationHelper.OpenOrCreateDatabase(String databaseFilePath)
[xUnit.net 00:00:01.41]         D:\a\1\s\Reusable.DataAccess.Sqlite.IntegrationTests\SqliteDatabaseFixture.cs(17,0): at Reusable.DataAccess.Sqlite.IntegrationTests.SqliteDatabaseFixture..ctor()
[xUnit.net 00:00:01.41]         D:\a\1\s\Reusable.DataAccess.Sqlite.IntegrationTests\SqliteDatabaseCreationHelperTest.cs(22,0): at Reusable.DataAccess.Sqlite.IntegrationTests.SqliteDatabaseCreationHelperTest..ctor()
[xUnit.net 00:00:01.41]         ----- Inner Stack Trace -----
[xUnit.net 00:00:01.41]            at Microsoft.Data.Sqlite.Utilities.ApplicationDataHelper.GetFolderPath(String propertyName)
[xUnit.net 00:00:01.41]            at Microsoft.Data.Sqlite.Utilities.ApplicationDataHelper.get_LocalFolderPath()
[xUnit.net 00:00:01.41]            at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize()
[xUnit.net 00:00:01.41]            at Microsoft.Data.Sqlite.SqliteConnection..cctor()

If I rollback to package version 5.0.12, then it works normally again.

This bug can be reproduced by running Reusable.DataAccess.Sqlite.IntegrationTests from this build of my project:
https://github.com/faburaya/dotNetReusable/commit/b085274e8126bb22a5d0b720b8aa9ef63c73849c

Further details of the failure can be found here:
https://dev.azure.com/faburaya/Reusable.NET/_build/results?buildId=15&view=results

@jonreis
Copy link

jonreis commented Nov 18, 2021

I am having the same issue using .NET Framework non-sdk style projects and AnyCPU.

I thought it was a bug in SQLitePCLRaw.bundle_e_sqlcipher that was fixed in v2.0.7 but I have included that version (see: ericsink/SQLitePCL.raw#451) and I am still seeing the same issue.

@ajcvickers
Copy link
Contributor

@faburaya @jonreis This looks like a duplicate of #26574, which is fixed for the 6.0.1 release. Can you try with the daily build, which is EF7, but contains the fixes for 6.0.1, and report back?

@jonreis
Copy link

jonreis commented Nov 18, 2021

@ajcvickers I can confirm this works fine in version: 7.0.0-alpha.1.21568.2. Thank you.

@faburaya
Copy link
Author

@ajcvickers ,
I will not be able to test this patch since I cannot leave netcore v3.1.
But it seems like you really have the fix.
I will wait for the next stable nuget package.

@ajcvickers
Copy link
Contributor

@faburaya Microsoft.Data.Sqlite in the daily feed will still run on .NET Core 3.1. It's only the EF stuff that requires .NET 6.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants