如何在xamarin中使用Microsoft.EntityFrameworkCore.Sqlite进行完整链接? 链接用户程序集

问题描述

一个制作了Xamarin表单的应用程序,现在我正在尝试制作一个Android发行版(目标api29。最低23)。当链接sdk程序集仅处于活动状态,而不能在完全链接中运行时,应用程序在启动时崩溃。

我有异常(Full excetion)您可以在异常link中看到DatabaseHelper

system.invalidOperationException: A suitable constructor for type 'Microsoft.EntityFrameworkCore.sqlite.Diagnostics.Internal.sqliteLoggingDeFinitions' Could not be located. Ensure the

system.invalidOperationException: A suitable constructor for type 'Microsoft.EntityFrameworkCore.Diagnostics.Internal.DbConnectionInterceptorAggregator' Could not be located. Ensure the

我的上下文

[Preserve(AllMembers = true)]
    public class meAppDatabaseContext : DbContext
    {
        private const string databaseName = "dummy.db";
        public virtual DbSet<..> ..{ get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            string databasePath = "";
            switch (Device.RuntimePlatform)
            {
                case Device.iOS:
                    Batteries_V2.Init();
                    databasePath = ath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),"..","Library",databaseName);              
                    break;
                case Device.Android:
                    databasePath = Path.Combine(FileSystem.AppDataDirectory,databaseName);
                    break;
                default:
                    throw new NotImplementedException("Platform not supported");
            }
            optionsBuilder.Usesqlite($"Filename={databasePath}");
        }
    }

我试图添加proguard.cfg

-keep public class Microsoft.EntityFrameworkCore.**
-keep public class Microsoft.EntityFrameworkCore.sqlite.**
-keep public class Microsoft.EntityFrameworkCore.sqlite.Diagnostics.Internal.sqliteLoggingDeFinitions
-keep public class Microsoft.EntityFrameworkCore.Diagnostics.Internal.DbConnectionInterceptorAggregator

我试图创建LinkerDescription.xml

<linker>
    <assembly fullname="Microsoft.EntityFrameworkCore">
        <type fullname="Microsoft.EntityFrameworkCore.Internal.sqliteLoggingDeFinitions"></type>
        <type fullname="Microsoft.EntityFrameworkCore.Internal.DbConnectionInterceptorAggregator"></type>
...

我尝试添加AndroidLinkSkip

<AndroidLinkSkip>
Microsoft.EntityFrameworkCore.sqlite.Diagnostics.Internal.sqliteLoggingDeFinitions;
Microsoft.EntityFrameworkCore.Diagnostics.Internal.DbConnectionInterceptorAggregator;
Microsoft.EntityFrameworkCore.sqlite;
Microsoft.EntityFrameworkCore;
</AndroidLinkSkip>

我试图在MainActivity.cs和App.cs中使用

var a = typeof(Microsoft.EntityFrameworkCore.Diagnostics.Internal.DbConnectionInterceptorAggregator);
var b = typeof(Microsoft.EntityFrameworkCore.sqlite.Diagnostics.Internal.sqliteLoggingDeFinitions);
var c= typeof(Microsoft.EntityFrameworkCore.Internal.SingletonoptionsInitializer);

试图致电mainactivity.cs

 Batteries_V2.Init();

有小费吗?

最新的VS19社区和VS19企业预览,所有软件包均为最新版本(我尝试过预览entytyfreamwork和sqlite软件包,相同的问题)。网络标准2.1 R8 + D8

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)