ericsink / SQLitePCL.raw

A Portable Class Library (PCL) for low-level (raw) access to SQLite
Apache License 2.0
525 stars 109 forks source link

Problem with provider dynamic on .NET Framework seen with Akavache #285

Closed ericsink closed 4 years ago

ericsink commented 5 years ago

Not sure if this is related or not, but after upgrading Akavache from v6.5.20 to v6.7.1 and SQLitePCLRaw.bundle_e_sqlite3 from v1.1.14 to v2.0.0 when trying to initialize Akavache I get the following exception:

Unhandled exception: System.TypeInitializationException: The type initializer for "Akavache.BlobCache" threw an exception. ---> System.ArgumentException: Path is invalid.
   in System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   in System.IO.Path.InternalGetDirectoryName(String path)
   in SQLitePCL.NativeLibrary.MakePossibilitiesFor(String basename, Assembly assy, Int32 flags, LibSuffix suffix)
   in SQLitePCL.NativeLibrary.MyLoad(String basename, Assembly assy, Int32 flags, Action`1 log)
   in SQLitePCL.NativeLibrary.Load(String libraryName, Assembly assy, Int32 flags)
   in SQLitePCL.Batteries_V2.MakeDynamic(String name, Int32 flags)
   in SQLitePCL.Batteries_V2.DoDynamic_cdecl(String name, Int32 flags)
   in SQLitePCL.Batteries_V2.Init()
   in Akavache.Registrations.Register(IMutableDependencyResolver resolver, IReadonlyDependencyResolver readonlyDependencyResolver)
   in Akavache.DependencyResolverMixin.InitializeAkavache(IMutableDependencyResolver resolver, IReadonlyDependencyResolver readonlyDependencyResolver)
   in Akavache.BlobCache.<>c.<.cctor>b__9_0()
   in Splat.InternalLocator.RegisterResolverCallbackChanged(Action callback)
   in Splat.Locator.RegisterResolverCallbackChanged(Action callback)
   in Akavache.BlobCache..cctor()

The exception is thrown from here: https://github.com/worldbeater/Camelotia/blob/misc-updates/src/Camelotia.Presentation.Wpf/App.xaml.cs#L24 Planning to investigate what's causing this later, but any ideas of what could go wrong with Akavache are appreciated. The repro is here, misc-updates branch, Camelotia.Presentation.Wpf project. Akavache initializes without exceptions and works fine when targeting .NET Core (Camelotia.Presentation.Avalonia) or UWP (Camelotia.Presentation.Uwp), breaks only when targeting .NET Framework (WPF)

Originally posted by @worldbeater in https://github.com/ericsink/SQLitePCL.raw/issues/282#issuecomment-520226926

ericsink commented 5 years ago

My own comment from the other issue: "At first glance, this looks like a bug in SQLitePCLRaw. A bug that is specific to .NET Framework. I need to look more closely."

ericsink commented 4 years ago

I was able to reproduce this problem.

First I simply grabbed the repro projects, and run the Wpf project. It works fine.

Then if I change the akavache and SQLitePCLRaw versions as you specify, and run the project, I get the error shown above.

I began to wonder what else is going on, because it seemed like if akavache with SQLitePCLRaw 2.0 is so broken, everybody would be screaming.

So I looked for other things about this repro app that were different.

The Fody Costura stuff was the obvious suspect.

If I remove those things from the csproj and run the app again, it works fine.

Microlife-JasonLi commented 4 years ago

I have this issue too. I can't use sqlite-pcl with SQLitePCLRaw 2.0

ericsink commented 4 years ago

@Microlife-JasonLi Please post complete details of your situation in a new issue.

softlion commented 4 years ago

@Microlife-JasonLi use this drop in replacement for akavache. The problem really lives in akavache, not sqlitepcl. I had the problem at Airbus and rewrote akavache in 2 hours, then thoroughly tested it. All crash gone...

https://github.com/softlion/KeyValueLite

ericsink commented 4 years ago

FWIW, if there is a problem with Akavache and SQLitePCLRaw, I would like to understand it in depth and find a solution rather than simply suggest alternatives to Akavache.

softlion commented 4 years ago

@ericsink there is a locking problem of sql queries. The db is not multithread safe. Even if it advertises to be so. Simple C# lock() statement are not enough (like akavache is using). lock statements don't work when using Tasks, because of the way Tasks are scheduled on threads (tasks != threads).

anaisbetts commented 3 years ago

@softlion Akavache.SQLite3 delegates all database queries / inserts to a single thread, which means that it doesn't need locks

softlion commented 3 years ago

@softlion Akavache.SQLite3 delegates all database queries / inserts to a single thread, which means that it doesn't need locks

If that was really working I would still use it. But it does not.