7

我在 ASP.NET Core 2.0 预览版上使用 Pomelo 1.1.2 以及 EF 2.0 预览版。使用他们的演示代码,每次调用“UseMySql”时都会出现以下异常:

System.TypeLoadException occurred
  HResult=0x80131522
  Message=Method 'Clone' in type 'Microsoft.EntityFrameworkCore.Internal.MySqlOptionsExtension' from assembly 'Pomelo.EntityFrameworkCore.MySql, Version=1.1.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
  Source=<Cannot evaluate the exception source>
  StackTrace:
   at Microsoft.EntityFrameworkCore.MySqlDbContextOptionsExtensions.UseMySql(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 mySqlOptionsAction)
   at CoreTest1.Startup.<ConfigureServices>b__4_0(DbContextOptionsBuilder options) in C:\DEV\Experiments\CoreTest1\CoreTest1\Startup.cs:line 27
   at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.<>c__DisplayClass0_0`1.<AddDbContext>b__0(IServiceProvider p, DbContextOptionsBuilder b)
   at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.DbContextOptionsFactory[TContext](IServiceProvider applicationServiceProvider, Action`2 optionsAction)
   at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.<>c__DisplayClass5_0`1.<AddCoreServices>b__0(IServiceProvider p)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactoryService(FactoryService factoryService, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass17_0.<RealizeService>b__0(ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at CoreTest1.Controllers.HomeController.Index() in C:\DEV\Experiments\CoreTest1\CoreTest1\Controllers\HomeController.cs:line 18
   at Microsoft.AspNetCore.Mvc.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__18.MoveNext()

想知道这是否仅仅是因为 2.0 预览库?有任何想法吗?我试图在 Git 上查看他们的源代码,看看我是否可以立即发现任何错误,但不能。

4

3 回答 3

9

让我们看一下 EF Core 2.0 Preview 1公告

如果您使用的是第三方数据库提供商,请检查他们是否发布了依赖于 2.0.0-preview1-final 的更新。如果他们有,那么只需升级到新版本。如果没有,那么您将无法升级,因为 2.0 版包含几个重大更改,并且 1.* 提供者不希望使用它。

这意味着在产生可比较的版本之前,Pomelo 预计不会支持 EF Core 2.0 。

于 2017-05-15T18:32:22.600 回答
2

最近,在我的项目更新到 .NET Core 2.0 时遇到了同样的错误。目前解决方案描述在https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql 基本上更新包到预发布版本2.0.0-rc-*

<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.0-rc-*" />
于 2017-08-19T15:13:06.313 回答
0

如果您使用的是asp.net core 2.0,则需要使用pomelo 2.0.0。Asp.net core 2.0 不适用于 pomelo 2.1 或更高版本。

于 2018-11-30T12:00:08.117 回答