c# - .Net Standard 2.0 SQLite.Core 程序集在单元测试中找不到
问题描述
我一直在开发一个 .Net 标准库,它可以进行大量 API 调用,并且其中一些 API 调用需要与 API 提供的 SQLite 数据库进行交叉引用。我正在与 .Net 标准库一起开发一个单元测试项目来测试一切是否正常,以及让一个单元测试项目与库一起增长是很棒的。我写了一段代码,希望能让我轻松访问那个 SQLite DB 但是,我得到了
找不到程序集错误:System.IO.FileNotFoundException:'无法加载文件或程序集'System.Data.SQLite,版本 = 1.0.109.0,文化 = 中性,PublicKeyToken = db937bc2d44ff139'。该系统找不到指定的文件。
我继续安装了 nugets 包
- SQLite
- System.Data.SQLite
- System.Data.SQLite.Core
进入我的 .Net 标准库和我的单元测试项目。
尝试创建此类的新实例后,我在单元测试中遇到错误。
我的数据访问类:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace D2DataAccess.SqLite
{
public class SQLiteDestinyEngine
{
private readonly SQLiteConnection Connection;
public SQLiteDestinyEngine(FileInfo LocalPath)
{
var builder = new SQLiteConnectionStringBuilder { DataSource = LocalPath.FullName };
Connection = new SQLiteConnection(builder.ToString());
}
public async Task<Dictionary<long, T>> GetDetailedInformationFromHash<T>(string TableName, params long[] itemHashes)
{
return await await Task.Factory.StartNew(async () =>
{
var dataSet = new Dictionary<long, T>();
var query = $"select id, json from '{TableName}' where id in (@hashes)";
using (var command = new SQLiteCommand(query, Connection))
{
command.Parameters.AddWithValue("@hashes", itemHashes);
var reader = await command.ExecuteReaderAsync();
while (await reader.ReadAsync())
{
dataSet.Add(reader.GetInt64(0), JsonConvert.DeserializeObject<T>(reader.GetString(1)));
}
}
return dataSet;
}).ConfigureAwait(false);
}
}
}
解决方案
推荐阅读
- java - 检索分号前的单词
- algorithm - 有什么公式可以在没有循环的情况下在 Bresenham 的 2D 线中获得点?
- c# - Selenium ChromeDriver C# - 如何向浏览器发送快捷键
- asp.net - 发布新复选框列表时不会覆盖复选框列表
- python - 使用 mysql 数据库通过电子邮件进行 django 身份验证
- google-compute-engine - Cloud shell 找不到 Windows 实例
- python-3.x - python - 如何防止类生成具有早期实例化中使用的属性的对象,但不停止代码
- leaflet - 传单:如何在左侧/右侧创建窗格而不是弹出窗口
- c - 分数与下一个5的倍数之间的差值小于3,然后将分数四舍五入到下一个5的倍数。低于50的分数将不会升级
- reactjs - 无法在反应应用程序中使用 Ant design 的抽屉