gabsferreira
gabsferreira

Reputation: 3137

System.TypeLoadException at OnConfiguring method

I have a simple context class that maps to a local SQL Server database.

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;
            }

        }
    }

When I run the app create an instance of it, I get this error when the method UseSqlServer runs:

System.TypeLoadException: 'Method 'Clone' in type 'Microsoft.EntityFrameworkCore.Infrastructure.Internal.SqlServerOptionsExtension' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.'

I already googled and apparently this error happens when the connection string is wrong. However, I already tested it opening a connection with a SQLConnection object and it's fine.

Upvotes: 1

Views: 1271

Answers (1)

gabsferreira
gabsferreira

Reputation: 3137

I solved this by installing the latest version of Microsoft.EntityFrameworkCore.SqlServer. I was using version 1.1.0 and I had the latest version of Microsoft.EntityFrameworkCore.Tools. Now both are 2.1.4.

Upvotes: 5

Related Questions