Getting error when trying to add migration in dotnet core 3.1 related to Pomelo.EntityFrameworkCore.MySql
M

2

7

I'm getting this error when,

dotnet ef migrations add InitialMigration

Method 'Create' in type 'Pomelo.EntityFrameworkCore.MySql.Query.ExpressionVisitors.Internal.MySqlSqlTranslatingExpressionVisitorFactory' from assembly 'Pomelo.EntityFrameworkCore.MySql, Version=3.2.3.0, Culture=neutral, PublicKeyToken=2cc498582444921b' does not have an implementation.

Entity Framework Core .NET Command-line Tools 5.0.0-rc.2.20475.6

Full error -

Build started...
Build succeeded.
System.TypeLoadException: Method 'Create' in type 'Pomelo.EntityFrameworkCore.MySql.Query.ExpressionVisitors.Internal.MySqlSqlTranslatingExpressionVisitorFactory' from assembly 'Pomelo.EntityFrameworkCore.MySql, Version=3.2.3.0, Culture=neutral, PublicKeyToken=2cc498582444921b' does not have an implementation.
   at Microsoft.Extensions.DependencyInjection.MySqlServiceCollectionExtensions.AddEntityFrameworkMySql(IServiceCollection serviceCollection)    
   at Pomelo.EntityFrameworkCore.MySql.Infrastructure.Internal.MySqlOptionsExtension.ApplyServices(IServiceCollection services)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.ApplyServices(IDbContextOptions options, ServiceCollection services)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>g__BuildServiceProvider|3()
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>b__2(Int64 k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)
   at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
   at Commander.Data.CommanderContext..ctor(DbContextOptions`1 opt) in D:\.NET\project02\data\CommanderContext.cs:line 8
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext 
context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope) 
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass13_3.<FindContextTypes>b__11()
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at 

Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Method 'Create' in type 'Pomelo.EntityFrameworkCore.MySql.Query.ExpressionVisitors.Internal.MySqlSqlTranslatingExpressionVisitorFactory' from assembly 'Pomelo.EntityFrameworkCore.MySql, Version=3.2.3.0, Culture=neutral, PublicKeyToken=2cc498582444921b' does not have an implementation.

Dependencies -

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-rc.2.20475.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0-rc.2.20475.6">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.3" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
  </ItemGroup>


</Project>

appsetting.js

 "ConnectionStrings": 
  {
    "DefaultConnection": "server=localhost;port=3306;database=CommanderDB;uid=root;password=ishanah"
  }

startup.cs -

  public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddDbContext<CommanderContext>(options =>
        options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));

            services.AddScoped<ICommanderRepo, MockCommanderRepo> ();
        }
Misdate answered 19/10, 2020 at 12:11 Comment(0)
H
7

Pomelo 3.2.3 is not compatible with EF Core 5 (see Compatibility). You currently need to use an alpha prerelease from nuget.org our from our nightly build feed to use EF Core 5.

For more information, take a look at EF Core 5 Preview support:

Hallucinosis answered 19/10, 2020 at 12:54 Comment(7)
What if I use Entity Framework Core .NET Command-line Tools 3.1.9 what pomelo version should I use. Because it also getting the same errorMisdate
I tried pomola 3.2.3 & 3.0.1 with EF Core 3.1.9 and still getting the error . .NET Core SDK (3.1.302)Misdate
I found compatible versions, Thank YouMisdate
<ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.3" /> </ItemGroup>Misdate
The link to the compatibility matrix is in my answer. Use the same EF Core CLI tool version as the EF Core version.Hallucinosis
Works nicely, but I get this error Error CS1503 Argument 2: cannot convert from 'string' to 'Microsoft.EntityFrameworkCore.ServerVersion' on this services.AddDbContext<AppIdentityDbContext>( options => options.UseMySql(Configuration["ConnectionStrings:AuthConnection"]));Concoct
@GeraldHughes Use options.UseMySql(Configuration["ConnectionStrings:AuthConnection"], ServerVersion.AutoDetect(Configuration["ConnectionStrings:AuthConnection"])) instead. See the sample code or the pull request on our GitHub repo.Hallucinosis
E
5

I already resolved this problem. Just upgrade the same version for both EF core and Pomelo.EntityFrameworkCore.MySql : 5.x. Just take a note that you should use Pomelo in version 5.0 alpha 1 ( not alpha 2) to make the start up file run correctly.

Erida answered 22/1, 2021 at 4:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.