OnConfiguring 方法中的 System.TypeLoadException

gab*_*ira 1 .net c# entity-framework entity-framework-core

我有一个映射到本地 SQL Server 数据库的简单上下文类。

public class LojaContext : DbContext
    {
        public DbSet<Produto> Produtos { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            try
            {
                if (!optionsBuilder.IsConfigured)
                {
                    optionsBuilder.UseSqlServer("Data Source=(localdb)\\ProjectsV13;Initial Catalog=LojaDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }

        }
    }
Run Code Online (Sandbox Code Playgroud)

当我运行该应用程序时,创建它的一个实例,该方法UseSqlServer运行时出现此错误:

System.TypeLoadException: 来自程序集“Microsoft.EntityFrameworkCore.SqlServer, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60”的“Microsoft.EntityFrameworkCore.Infrastructure.Internal.SqlServerOptionsExtension”类型中的“Method 'Clone”没有实现.'

我已经用谷歌搜索过,显然当连接字符串错误时会发生此错误。但是,我已经测试了它打开与SQLConnection对象的连接,这很好。

gab*_*ira 5

我通过安装最新版本的Microsoft.EntityFrameworkCore.SqlServer. 我正在使用 version1.1.0并且我拥有最新版本的Microsoft.EntityFrameworkCore.Tools. 现在都是 2.1.4。