System.Typeloadexception

Asked

Viewed 77 times

1

I’m most likely not able to connect my application to my database with Entity Framework Core, as this error keeps popping up whose I can’t decipher.

I have already researched the documentation and tried to do several things.

In addition, I also can’t work with Entity Framework mapping my model, as a message appears saying that user and server credentials are missing.

Source Code:

public AgendaContext() : base()
        {

        }
        protected override void OnConfiguring (DbContextOptionsBuilder builder)
        {
            builder.UseMySQL("server=localhost;database=trabalho;user=root;password=123456789");
        }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.Entity<Agenda>()
                   .ToTable("tb_agenda");

            builder.Entity<Agenda>()
                   .HasKey(p => p.AgendaID);

            builder.Entity<Agenda>()
                   .Property(p => p.Nome)
                   .HasColumnType("varchar(80)");

            builder.Entity<Agenda>()
                   .Property(p => p.Endereco)
                   .HasColumnType("varchar(255)");

            builder.Entity<Agenda>()
                   .Property(p => p.DiaCompromisso)
                   .HasColumnType("date");

            builder.Entity<Agenda>()
                   .Property(p => p.HoraCompromisso)
                   .HasColumnType("time");

            builder.Entity<Agenda>()
                   .Property(p => p.Final)
                   .HasColumnType("time");
        }

        public DbSet<Agenda> Agenda { get; set; }

Error:

System.Typeloadexception: 'get_Info method on type MySql.Data.EntityFrameworkCore.Infraestructure.MySQLOptionsExtension from Assembly Mysql.Data.Entityframeworkcore, Version=8.0.18.0, Culture=neutral, Publickeytoken=c5687fc88969c44d does not have a implementation.'

1 answer

1

As the discussion cited by Felipe: https://github.com/dotnet/efcore/issues/17788 is in fact a BUG, in case the official fix has not yet come out, however it is suggested to install the package.

With PM:

Install-Package Pomelo.EntityFrameworkCore.MySql

Dotnet:

dotnet add package Pomelo.EntityFrameworkCore.MySql

After installed the configuration follows like this https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#3-services-Configuration:

using System;
using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;

namespace FooBar
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            // Troque SeuContexto pela classe do seu DbContext
            services.AddDbContextPool<SeuContexto>(options => options
                // ajuste os dados de conexão
                .UseMySql("Server=localhost;Database=ef;User=root;Password=1234;", mySqlOptions => mySqlOptions
                    // Ajuste a versão do seu servidor
                    .ServerVersion(new ServerVersion(new Version(8, 0, 18), ServerType.MySql))
            ));
        }
    }
}
  • Thank you, however, the code that was posted, I put where?

  • @Gustavooliveira but you no longer have Startup code in your project?

  • Startup no, but I put the codes directly in Dbcontext, because I don’t know much. Also, I tried to put in the starting point of my program and it did not work....

  • Because I’m using Entity Framework Core on. Net Framework, IE, I’m using a Windows Forms application, so I’m not able to make the connection...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.