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

Does SQLite-net-pcl support .NET 6.0 and .NET Maui? #1102

Open
IndianaGary opened this issue Feb 23, 2022 · 12 comments
Open

Does SQLite-net-pcl support .NET 6.0 and .NET Maui? #1102

IndianaGary opened this issue Feb 23, 2022 · 12 comments

Comments

@IndianaGary
Copy link

IndianaGary commented Feb 23, 2022

I've been using SQLite-net-pcl with nearly all my Xamarin Forms projects for nearly 3 years and I am about to port some of them to .NET Maui. I am blocked from doing so at this point for lack of an equivalent SQLite implementation; or, at least, I'm unaware of the existence of one. I really don't want to have to rewrite my data access code if I can avoid it, but at this point, I need to make a move soon. I really don't like the overhead of EF and I am unsure of whether any of the SQLite NuGet packages are viable. I really like the simplicity of the current implementation.

My question is: are there plans to provide equivalent functionality for .NET 6.0 and .NET Maui?

I thank you for your past efforts and hope that the future brings SQLite to .NET 6 and Maui.

UPDATE: I just discovered #1056 from August of last year. Unless something undocumented has occurred in the last 7-8 months, I can't say I'm very optimistic about the future.

@IndianaGary IndianaGary changed the title How to use SQLite-net-pcl with .NET 6.0 and .NET Maui Does SQLite-net-pcl support .NET 6.0 and .NET Maui? Feb 23, 2022
@ZoranUnkovic
Copy link

I can confirm it works (tested on win/android) using latest SQLitePCLRaw 2.1.0 prerelease.

@jfversluis
Copy link

Hey @IndianaGary! Just like @ZoranUnkovic I find that it "just works" ™️

I have to add these to my .NET MAUI csproj (see underneath) but with that it works as before.

<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.0-pre20220207221914" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.0-pre20220207221914" />
<PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.0-pre20220207221914" />
<PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.0-pre20220207221914" />

@IndianaGary
Copy link
Author

Hi Gerald, yes, I confirmed that it works just last week.

Regards, Gary

@soundaranbu
Copy link

When I tried it, the app works normally in debug mode. But when deployed in release mode, encountering the following startup crash in .NET 6, MAUI RC3, Android 11

Time	Device Name	Type	PID	Tag	Message
05-19 08:49:09.787	pixel_5_-_api_30	Info	24210	MonoDroid	android.runtime.JavaProxyThrowable: System.TypeInitializationException: TypeInitialization_Type, SQLite.SQLiteConnection
 ---> System.TypeLoadException: Could not load list of method overrides due to Method not found: int SQLitePCL.ISQLite3Provider.sqlite3_load_extension(SQLitePCL.sqlite3,SQLitePCL.utf8z,SQLitePCL.utf8z,SQLitePCL.utf8z&)
   at SQLite.SQLiteConnection..cctor()
   Exception_EndOfInnerExceptionStack
   at MauiApp1.Service.LedgerRepository.get_Connection()
   at MauiApp1.Service.LedgerRepository.Init()
   at MauiApp1.App..ctor(LedgerRepository ledgerRepository)
   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object , Object[] , Boolean )
   at System.Reflection.RuntimeConstructorInfo.DoInvoke(Object , BindingFlags , Binder , Object[] , CultureInfo )
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags , Binder , Object[] , CultureInfo )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type )
   at System.Collections.Concurrent.ConcurrentDictionary`2[[System.Type, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Func`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope, Microsoft.Extensions.DependencyInjection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(Type , Func`2 )
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type , ServiceProviderEngineScope )
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type )
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider , Type )
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[IApplication](IServiceProvider )
   at Microsoft.Maui.MauiApplication.OnCreate()
   at Android.App.Application.n_OnCreate(IntPtr , IntPtr )
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr )
	at crc6488302ad6e9e4df1a.MauiApplication.n_onCreate(Native Method)
	at crc6488302ad6e9e4df1a.MauiApplication.onCreate(MauiApplication.java:28)
	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712)
	at android.app.ActivityThread.access$1300(ActivityThread.java:237)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:223)
	at android.app.ActivityThread.main(ActivityThread.java:7656)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

@soundaranbu
Copy link

What finally worked for me is

<PublishTrimmed>false</PublishTrimmed>
<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
<PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.0-pre20220427180151" />

Hope it helps someone. Thanks

@beeradmoore
Copy link

Came across this issue right now. Looked into SQLitePCLRaw.provider.dynamic_cdecl and it seems the stable 2.1.0 came out literally 2 hours ago. Adding it didn't solve the problem for me but that is because sqlite-net-pcl was still referencing an older SQLitePCLRaw.bundle_green. If you reference this one then SQLitePCLRaw.provider.dynamic_cdecl will also reference the updated one.

However it's still somewhat broke here.

iOS simulator debug runs fine.
Can't deploy debug or release builds to iOS device for unknown reasons.
macOS debug dies with ---> System.DllNotFoundException: sqlite3
Android device release build appears to work fine.

@ericsink
Copy link
Contributor

@beeradmoore Please log an issue in the SQLitePCL.raw repo and include full details of your configuration and the error. If possible, attach a minimal reproduction project.

@beeradmoore
Copy link

@ericsink done

@matt-goldman
Copy link

Hey @IndianaGary! Just like @ZoranUnkovic I find that it "just works" ™️

I have to add these to my .NET MAUI csproj (see underneath) but with that it works as before.

<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.0-pre20220207221914" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.0-pre20220207221914" />
<PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.0-pre20220207221914" />
<PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.0-pre20220207221914" />

I've found that this workaround from @jfversluis works for Android, but it works without it on Windows, and breaks it on Windows if included. Adding Condition="'$(TargetFramework)' == 'net6.0-android'" to these includes got around that problem for me.

@jwoeste
Copy link

jwoeste commented Aug 18, 2022

Just working on a net6 project on a M1 Mac.

Using sqlite-net-pcl did not work (as previously reported by @beeradmoore : macOS debug dies with ---> System.DllNotFoundException: sqlite3)

The workaround I found for the net6 project is to add these package references to the .csproj

<PackageReference Include="SQLitePCLRaw.core" Version="2.1.0-pre20220207221914" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.0-pre20220207221914" />
<PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.0-pre20220207221914" />
<PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.0-pre20220207221914" />

and add SQLite.cs and SQLiteAsync.cs directly to the project.

I will test that this also works for windows, linux, iOS and android in a foreseeable future.

If this works then the issue could be somewhere in the packaging of sqlite-net-pcl in terms on selecting the correct platform target?

@beeradmoore
Copy link

That issues I reported went away with an update. I don't recall if it was workload, SDK, dotnet, or IDE. I may have said it in the issue before I closed it.

For those iOS/macOS at least it working out of the box again.

@thomiel
Copy link

thomiel commented Aug 25, 2022

My experience with Maui was that it worked fine for WinUI but when switching to the Android platform, I got an "Unable to load DLL 'e_sqlite3'" error. I then took a look at Vladislav Antonyuks MauiSamples ( https://github.com/VladislavAntonyuk/MauiSamples ) that worked well. The only difference to my code was that he didn't host the database service in the main Maui project but in a subproject, referencing the four SQLitePCLRaw.* packages in the main project and only the sqlite-net in the subproject. After I changed my code accordingly, the DLL load exception went away.

Iga-Entap added a commit to entap/Entap.Basic.Maui that referenced this issue Sep 29, 2022
・実行時のDllNotFoundException回避のためSQLitePCLRaw追加
praeclarum/sqlite-net#1102

・以下のエラー回避のため、AssemblyAttributesの生成を無効化
https://stackoverflow.com/questions/61997928/errorcs0579duplicate-globalsystem-runtime-versioning-targetframeworkattribu
.NETCoreApp,Version=v6.0.AssemblyAttributes.cs(12,12): Error CS0579: 'global::System.Runtime.Versioning.TargetFrameworkAttribute' 属性が重複しています (CS0579)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants