UWP - 在本机编译时出现SQLite问题

时间:2016-11-28 13:28:15

标签: c# sqlite raspberry-pi uwp iot

我正在使用SQLite开发我的应用程序,在" Debug"模式,工作得很好。

当我尝试"发布"它(编译" Native"),问题开始了,看起来像UWP不支持Reflexion。

我目前正在使用此套餐:

SQLite.Core.UAP
SQLite.Net-PCL

例如,如果我尝试这样做:

  private void CreateDatabase()
    {
        var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "StoredEvents.sqlite");
        SQLiteConnection SQLiteConn = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath, false);

        SQLiteConn.CreateTable<StoredEvents>();            
    }

这些是一些错误:

ILTransform_0027: Method 'CreateLambda' within 'System.Linq.Expressions.Expression' could not be found. 


Error at SerializationAssemblyGenerator.Program.AddKnownContractsLists(McgCodeTypeDeclaration container, ContractTables tables) 


Severity    Code    Description Project File    Line    Suppression State
Error       at SerializationAssemblyGenerator.Program.GenerateDataContractSerializerHelperCode(IEnumerable`1 contracts, IEnumerable`1 jsonContracts, IEnumerable`1 wcfSerializers)  



ILTransform_0000:       MCG : warning MCG0006: Unresolved P/Invoke method '_TPM_Init!tpm.dll' in assembly 'TSS.UWP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it is not available in UWP applications. Please either use an another API , or use [DllImport(ExactSpelling=true)

我应该如何重构代码?

我应该使用不同的图书馆吗?

1 个答案:

答案 0 :(得分:0)

当我将我的应用程序从Silverlight更新为UWP时,我遇到了同样的问题。我在某个地方读过一篇文章(试图找到它但却无法找到),其中说用于UWP的SQLlite可用于Windows 10部署。

enter image description here

以上是VS扩展。你可以从Tools - &gt;&gt;到达那里。扩展程序&amp;更新

以下是我的参考资料的样子。

enter image description here

此外,我注意到您没有关闭数据库连接。总是更好地在using语句中使用它。您的CreateTables()将如下所示。

private void CreateDatabase()
{
    var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "StoredEvents.sqlite");
    using (SQLiteConnection SQLiteConn = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath, false))
    {
        SQLiteConn.CreateTable<StoredEvents>();
    }     
}