Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Is it possible to create a Blazor Hybrid app that uses NHibernate and Sqlite on Android?

$
0
0

I suspect it's not possible, but I would appreciate community input on this topic.

I've created a .NET MAUI Blazor Hybrid app, as one project in a multi-project solution. I have an Infrastructure project that handles database interaction, along with some other projects following the Clean Architecture pattern. I am able to fully interact with the database when running the app on a Windows machine, no problem. But when I target Android (using one of the downloadable emulators in Visual Studio), things go off the rails.

When I add the "System.Data.Sqlite.Core" nuget package to my Infrastucture project, I get the "XAPRAS7009 System.InvalidOperationException: PE image does not have metadata." compilation error when trying to build the solution. The online suggestions that I've found for this problem is to remove that package reference. When I remove the "System.Data.Sqlite.Core" reference, the solution builds successfully, and everything works fine when targeting Windows Machine. The same dynamic happens when I use "System.Data.Sqlite" nuget package.

I can also then successfully deploy to the Android device, and step through the code as Services are added to the Builder in MauiProgram.cs.Note that I have nuget packages "NHibernate" and "Microsoft.Data.Sqlite" in the Infrastructure project.When it comes to calling "NHibernate.Cfg.Configuration.BuildSessionFactory() on the Android platform though, I get this error, which clearly states that "System.Data.SQLite" is required by NHibernate:

NHibernate.HibernateException: Could not create the driver from NHibernate.Driver.SQLite20Driver.---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.---> NHibernate.HibernateException: The DbCommand and DbConnection implementation in the assembly System.Data.SQLite could not be found. Ensure that the assembly System.Data.SQLite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use element in the application configuration file to specify the full name of the assembly.at NHibernate.Driver.ReflectionBasedDriver..ctor(String providerInvariantName, String driverAssemblyName, String connectionTypeName, String commandTypeName)at NHibernate.Driver.SQLite20Driver..ctor() etc.

I then searched the internet and found nothing that addresses this. Which leads me to wonder whether it is currently possible to use NHibernate to access a Sqlite database on an Android device, in a .NET MAUI Blazor Hybrid project?

For what it's worth, I'm currently trying to use NHibernate because I have a solid Repository class tailored for NHibernate (I use the Repository pattern), but if this is a dead end for Android, then I'll switch to a different way to access the Sqlite database (such as sqlite-net) and write a new IRepository implementation.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>