[UWP]发布配置会破坏实体框架和sqlite [英] [UWP]Release configuration breaks entity framework and sqlite

查看:69
本文介绍了[UWP]发布配置会破坏实体框架和sqlite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的构建遇到了严重问题。我在UWP应用程序中使用带有sqlite的实体框架。在调试模式下一切正常,但是当我在发布模式下运行应用程序时,我得到了很多sqlite /实体框架异常:


抛出异常:'Microsoft.Data.Sqlite.SqliteException'在Microsoft.Data.Sqlite.dll中$
抛出异常:Microsoft.Data.Sqlite.dll中的'Microsoft.Data.Sqlite.SqliteException'
$
异常抛出:'Microsoft。 Microsoft.Data.Sqlite.dll中的Data.Sqlite.SqliteException'$
抛出异常:Microsoft.Data.Sqlite.dll中的'Microsoft.Data.Sqlite.SqliteException'

抛出异常:Microsoft.Data.Sqlite.dll中的'Microsoft.Data.Sqlite.SqliteException'
$
抛出异常:Microsoft.EntityFrameworkCore.Relational.dll中的'Microsoft.Data.Sqlite.SqliteException'

异常抛出:Microsoft.EntityFrameworkCore.Relational.dll中的'Microsoft.Data.Sqlite.SqliteException'
$
抛出异常:Microsoft.EntityFrameworkCore.Relational中的'Microsoft.EntityFrameworkCore.DbUpdateException' 。 dll

异常抛出:Microsoft.EntityFrameworkCore.dll中的'Microsoft.EntityFrameworkCore.DbUpdateException'

异常抛出:Microsoft.EntityFrameworkCore.dll中的'Microsoft.EntityFrameworkCore.DbUpdateException' br />
异常抛出:System.Private.CoreLib.dll中的'Microsoft.EntityFrameworkCore.DbUpdateException'

抛出异常:System.Private.CoreLib中的'Microsoft.EntityFrameworkCore.DbUpdateException'。 dll

异常抛出:System.Private.CoreLib.dll中的'Microsoft.EntityFrameworkCore.DbUpdateException'
$
抛出异常:System.Private.Threading中的'System.InvalidOperationException'。 dll

异常抛出:System.Private.CoreLib.dll中的'System.InvalidOperationException'


我注意到如果我取消选中"优化代码"对于发布配置,一切都恢复正常。编译时发生了一些事情。有没有人知道如何调查这个?


解决方案

您好,Marius Bob,


欢迎
到开发通用Windows应用论坛!
 请使用   ; 标记  当
发布到此论坛时,谢谢!


我关注了博客  在UWP应用程序中使用SQLite数据库 创建一个样本,它运作良好,你也可以把它作为参考
并注意博客中的注释。


例如,


1.S Windows版本的SQLite仅在Windows 10周年更新后才可用,它只能用于面向Build 14393或更高版本的UWP应用程序。


2. 添加Microsoft.Data.Sqlite并升级.NET Core模板。


3.在制作任何其他模板之前调用SqliteEngine.UseWinSqlite3() App.xaml.cs中的SQL调用,它保证Microsoft.Data.Sqlite框架将使用SQLite的SDK版本而不是本地版本,如下面的代码。

 public App()
{
this.InitializeComponent();
this.Suspending + = OnSuspending;
SqliteEngine.UseWinSqlite3(); //配置库到使用SDK版本的SQLite
使用(SqliteConnection db = new SqliteConnection(" Filename = sqliteSample.db"))
{
db.Open();
String tableComma nd =" CREATE TABLE IF NOT NOT EXISTS MyTable(Primary_Key INTEGER PRIMARY KEY AUTOINCREMENT,Text_Entry NVARCHAR(2048)NULL)" ;;
SqliteCommand createTable = new SqliteCommand(tableCommand,db);
try
{
createTable.ExecuteReader();
}
catch(SqliteException e)
{
//什么都不做
}
}
}

更多详情,请参阅  在UWP应用程序中使用SQLite数据库并检查您的代码。


祝您好运,


Breeze


Hi,

I am stuck into a serious trouble with my build. I am using entity framework with sqlite in an UWP application. Everything works fine on debug mode, BUT when I run the app on release mode I got a lot of sqlite/entity framework exceptions:

Exception thrown: 'Microsoft.Data.Sqlite.SqliteException' in Microsoft.Data.Sqlite.dll
Exception thrown: 'Microsoft.Data.Sqlite.SqliteException' in Microsoft.Data.Sqlite.dll
Exception thrown: 'Microsoft.Data.Sqlite.SqliteException' in Microsoft.Data.Sqlite.dll
Exception thrown: 'Microsoft.Data.Sqlite.SqliteException' in Microsoft.Data.Sqlite.dll
Exception thrown: 'Microsoft.Data.Sqlite.SqliteException' in Microsoft.Data.Sqlite.dll
Exception thrown: 'Microsoft.Data.Sqlite.SqliteException' in Microsoft.EntityFrameworkCore.Relational.dll
Exception thrown: 'Microsoft.Data.Sqlite.SqliteException' in Microsoft.EntityFrameworkCore.Relational.dll
Exception thrown: 'Microsoft.EntityFrameworkCore.DbUpdateException' in Microsoft.EntityFrameworkCore.Relational.dll
Exception thrown: 'Microsoft.EntityFrameworkCore.DbUpdateException' in Microsoft.EntityFrameworkCore.dll
Exception thrown: 'Microsoft.EntityFrameworkCore.DbUpdateException' in Microsoft.EntityFrameworkCore.dll
Exception thrown: 'Microsoft.EntityFrameworkCore.DbUpdateException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.EntityFrameworkCore.DbUpdateException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.EntityFrameworkCore.DbUpdateException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.Threading.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll

I noticed that if I uncheck "Optimize code" for release configuration, everything is back to normal. Something is happening at compilation. Does anyone have any clue about how to investigate this?

解决方案

Hello Marius Bob,

Welcome to the Developing Universal Windows apps forum! Please utilize tagging when posting to this forum, thanks!

I followed the blog Using SQLite databases in UWP apps to create an sample, it worked well, you can also put it as a reference and pay attention to the Note in the blog.

For example,

1. Since the Windows SDK version of SQLite has only been available since the Windows 10 Anniversary Update, it can only be used for UWP apps targeting Build 14393 or higher.

2. Adding Microsoft.Data.Sqlite and upgrading the .NET Core template.

3. calling to SqliteEngine.UseWinSqlite3() before making any other SQL calls in the App.xaml.cs, which guarantees that the Microsoft.Data.Sqlite framework will use the SDK version of SQLite as opposed to a local version, as the following code.

        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;
            SqliteEngine.UseWinSqlite3(); //Configuring library to use SDK version of SQLite
            using (SqliteConnection db = new SqliteConnection("Filename=sqliteSample.db"))
            {
                db.Open();
                String tableCommand = "CREATE TABLE IF NOT EXISTS MyTable (Primary_Key INTEGER PRIMARY KEY AUTOINCREMENT, Text_Entry NVARCHAR(2048) NULL)";
                SqliteCommand createTable = new SqliteCommand(tableCommand, db);
                try
                {
                    createTable.ExecuteReader();
                }
                catch (SqliteException e)
                {
                    //Do nothing
                }
            }
        }

More details, please see Using SQLite databases in UWP apps and check your code.

Best regards,

Breeze


这篇关于[UWP]发布配置会破坏实体框架和sqlite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆