【问题标题】:SQLite3 Connection Causes Confusing Compile ErrorSQLite3 连接导致令人困惑的编译错误
【发布时间】:2015-08-13 11:35:50
【问题描述】:

我正在尝试编译我的 Xamarin 项目,但遇到了一个我不理解的编译器错误。以下错误是什么意思,我该如何解决?

Data\SQLiteClient.cs(4,4):错误 CS0012:“System.Threading.Tasks.TaskScheduler”类型在未引用的程序集中定义。您必须添加对程序集“System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”的引用。 (CS0012) (DtoToVm.Droid)

相关信息:

  • Xamarin Forms 空白项目 PCL
  • 项目设置为 .NET 4.5 或更高版本
  • 配置文件:PCL 4.5 - Profile78

很多参考都不满意,但我没有手动设置或编辑这些。也许是 nuget 包冲突?


using Xamarin.Forms;  
using DtoToVm.Droid.Data;

[assembly: Dependency (typeof(SQLiteClient))]
namespace DtoToVm.Droid.Data  
{
using System;
using DtoToVm.Data;
using SQLite.Net.Async;
using System.IO;
using SQLite.Net.Platform.XamarinAndroid;
using SQLite.Net;

public class SQLiteClient : ISQLite
{
    public SQLiteAsyncConnection GetConnection ()
    {
        var sqliteFilename = "Conferences.db3";
        var documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);

        var path = Path.Combine (documentsPath, sqliteFilename);

        var platform = new SQLitePlatformAndroid ();

        var connectionWithLock = new SQLiteConnectionWithLock (
            platform,
            new SQLiteConnectionString (path, true));


        // The below line causes the compile error
        var connection = new SQLiteAsyncConnection (() => connectionWithLock);

        return connection;
    }
}
}

编辑: 根据thread,我将配置文件更改为 7。我已经这样做了,它消除了所有错误,但产生了一个新错误:

DtoToVm\packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll: 错误 CS1703: 具有相同身份的程序集 'System .Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 已经被导入。尝试删除重复引用之一。 (CS1703) (DtoToVm)

这个重复的引用可能在哪个文件中?

【问题讨论】:

  • 您是否尝试将程序集“System.Threading.Tasks.TaskScheduler”添加到您的项目引用中?
  • 非常直接 - 它在异常中说 - “向您的项目添加对程序集 'System.Threading.Tasks' 的引用”
  • 有一个 SQLite PCL NuGet 可以为你省去很多麻烦 - nuget.org/packages/SQLite.Net-PCL

标签: c# .net sqlite xamarin


【解决方案1】:

我真的不知道 Xamarin 中是否存在 System.Threading.Tasks 命名空间,如果存在则引用它,如果不存在则使用常规 SqliteConnection 并且不要使用异步之一。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 2018-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多