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

Update from 5.0.1 to 6.0breaks all SqliteConnection #26574

Closed
pierresa opened this issue Nov 8, 2021 · 11 comments
Closed

Update from 5.0.1 to 6.0breaks all SqliteConnection #26574

pierresa opened this issue Nov 8, 2021 · 11 comments
Assignees
Labels
area-adonet-sqlite closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression Servicing-approved type-bug
Milestone

Comments

@pierresa
Copy link

pierresa commented Nov 8, 2021

File a bug

C# code like:

private static SqliteConnection DbConnectionPeoplePositionInPhoto
{
    get
    {
        var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = DBPathPeoplePositionInPhoto };
        string connectionString = connectionStringBuilder.ToString();
        return new SqliteConnection(connectionString);
    }
}

used to work fine.

Now I am getting:

System.TypeInitializationException: 'A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.'

Inner Exception
NullReferenceException: Object reference not set to an instance of an object.


System.TypeInitializationException
  HResult=0x80131534
  Message=A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

Inner Exception 1:
NullReferenceException: Object reference not set to an instance of an object.

Include version information

Microsoft.Data.Sqlite version: 6.0
Target framework: (e.g. .NET 5.0)
Operating system: Windows 11

@roji
Copy link
Member

roji commented Nov 8, 2021

@pierresa can you post the full exception details, including the stack trace? A code sample which shows this occurring would also help understand what's going on.

@pierresa
Copy link
Author

pierresa commented Nov 9, 2021

here is the stack:
KernelBase.dll!00007ffd4888466c() Unknown
mrt100_app.dll!00007ffd078aba21() Unknown
mrt100_app.dll!00007ffd078ab8e0() Unknown
mrt100_app.dll!00007ffd0789efed() Unknown
mrt100_app.dll!00007ffd0789f589() Unknown
mrt100_app.dll!00007ffd078a5cf7() Unknown
[External Code]
System.Private.CoreLib.dll!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Line 63 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task task) Line 188 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task) Line 155 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task task) Line 127 C#
System.Private.CoreLib.dll!System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult() Line 516 C#

Mon Gestionnaire de Photos.exe!MonGestionnaireDePhotos.MainPage.OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e) Line 67 C#
[External Code]
Mon Gestionnaire de Photos.exe!MonGestionnaireDePhotos.App.OnLaunched(Windows.ApplicationModel.Activation.LaunchActivatedEventArgs args) Line 160 C#
[External Code]

as for code sample, I just need the above code called with a "Using" as in the example online, it fails on "using"
using (var connection = DbConnectionPeoplePositionInPhoto)
{
}

@zhuxb711
Copy link

zhuxb711 commented Nov 9, 2021

Same in my UWP project

Dependency:
SQLitePCLRaw.bundle_e_sqlite3 v2.0.7
Microsoft.Data.Sqlite version v6.0.0

Example code:

        private SQLite()
        {
            SQLitePCL.Batteries_V2.Init();
            SQLitePCL.raw.sqlite3_win32_set_directory(1, ApplicationData.Current.LocalFolder.Path);
            SQLitePCL.raw.sqlite3_win32_set_directory(2, ApplicationData.Current.TemporaryFolder.Path);

            Connection = new SqliteConnection("Filename=Sqlite.db;");
            Connection.Open();

            InitializeDatabase();
        }

@sebastienros
Copy link
Member

Here is a stack trace :

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> 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()
[xUnit.net 00:00:08.46]     OrchardCore.Tests.Apis.GraphQL.BlogPostTests.ShouldNotBeAbleToExecuteAnyQueriesWithoutPermission [FAIL]
   at Microsoft.Data.Sqlite.SqliteConnection..cctor()

Reproes on GH actions on a Windows machine (ubuntu was fine) and didn't repro locally.

https://github.com/OrchardCMS/OrchardCore/runs/4146435675?check_suite_focus=true#step:8:1324

@ajcvickers
Copy link
Contributor

/cc @bricelam

@sebastienros
Copy link
Member

I think I isolated the issue. When running on netcoreapp3.1 the Windows.Storage.ApplicationData is found, but GetRuntimeProperty("LocalFolder") is null.

My tests work fine on net5.0 and net6.0 since it can't find the class, hence doesn't try to get this property.

@ajcvickers ajcvickers added this to the 6.0.x milestone Nov 10, 2021
bricelam added a commit to bricelam/efcore that referenced this issue Nov 11, 2021
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Nov 11, 2021
@pierresa
Copy link
Author

I see in response above "closed" ... well it is not closed for me The problem still exist and I do not see any update in nugets that I could apply

@sebastienros
Copy link
Member

@pierresa that is how we handle issue management. Once the bug is fixed in code it is closed, there is a milestone that describe when it will be shipped: 6.0.1.
The mitigation is to use the previous version of the package which works with .NET 6 too (5.0.12)

@ajcvickers
Copy link
Contributor

FYI for those impacted by this issue: EF Core 6.0.1 is now available from NuGet.

@ajcvickers ajcvickers changed the title update from 5.0.1 to 6.0breaks all SqliteConnection Update from 5.0.1 to 6.0breaks all SqliteConnection Dec 15, 2021
@riverar
Copy link

riverar commented Jul 20, 2023

This fix does not appear to have made it into Microsoft.Data.Sqlite 6.0.20.

@ajcvickers
Copy link
Contributor

@riverar Please open a new issue and attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-adonet-sqlite closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression Servicing-approved type-bug
Projects
None yet
Development

No branches or pull requests

8 participants