【问题标题】:System.TypeLoadException at OnConfiguring methodOnConfiguring 方法中的 System.TypeLoadException
【发布时间】:2018-10-22 17:47:26
【问题描述】:

我有一个映射到本地 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;
            }

        }
    }

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

System.TypeLoadException:来自程序集“Microsoft.EntityFrameworkCore.SqlServer,版本=1.1.0.0,文化=中性,PublicKeyToken=adb9793829ddae60”的“Microsoft.EntityFrameworkCore.Infrastructure.Internal.SqlServerOptionsExtension”类型中的“方法“克隆” ' 没有实现。'

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

【问题讨论】:

  • 该错误通常意味着在运行时找到的 .dll 不是针对编译的那个,除非您正在做一些非常奇怪的事情。建议尝试找出正在加载的 dll运行时以及为什么...

标签: c# .net entity-framework entity-framework-core


【解决方案1】:

我通过安装最新版本的Microsoft.EntityFrameworkCore.SqlServer 解决了这个问题。我使用的是1.1.0 版本,而我拥有最新版本的Microsoft.EntityFrameworkCore.Tools。现在都是 2.1.4。

【讨论】:

    猜你喜欢
    • 2019-06-17
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    相关资源
    最近更新 更多