新的 SqliteConnection("Filename=:memory:");在 connection.Open() 上给出 System.NullReferenceException;

new SqliteConnection("Filename=:memory:"); gives System.NullReferenceException on connection.Open();

我查看了使用 SQLite 内存数据库测试 Microsoft EF Core 应用程序的示例。

https://docs.microsoft.com/en-us/ef/core/testing/sqlite#using-sqlite-in-memory-databases

但是为 var connection = new SqliteConnection("Filename=:memory:"); 调用 connection.Open(); 给出了异常

System.NullReferenceException: 'Object reference not set to an instance of an object.'

var connection = new SqliteConnection("Data Source=:memory:");

的结果相同

我错过了什么?

public class QuestionUpdateTest: IDisposable
{

    private readonly DbConnection _connection;
    private readonly ApplicationDbContext _context = null;
        
    public ChoiceSequencingQuestionUpdateTest()
    {
        var dbContextOptions = new DbContextOptionsBuilder<ApplicationDbContext>()
                        .UseSqlite(CreateInMemoryDatabase())
                        .Options;
                        
        _connection = RelationalOptionsExtension.Extract(dbContextOptions).Connection;

        _context = new ApplicationDbContext(dbContextOptions);
    }
    
    private static DbConnection CreateInMemoryDatabase()
    {
        var connection = new SqliteConnection("Filename=:memory:");

        connection.Open();

        return connection;
    }

    public void Dispose() => _connection.Dispose();
    
    [Fact]
    public void Test2()
    {
        
    }
}

通过安装 NuGet Microsoft.EntityFrameworkCore.Sqlite 而不仅仅是 Microsoft.EntityFrameworkCore.Sqlite.Core 解决。记录非常少,其他包没有构建错误。感谢@ShahinDohan。