Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using Pomelo 6.0 Preview 6/7 together with EF Core 6.0 RC1 #1532

Closed
kyuranger opened this issue Oct 6, 2021 · 11 comments
Closed

Comments

@kyuranger
Copy link

kyuranger commented Oct 6, 2021

Here is my code:

using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace SIComponent.Database
{
    public class SIContext : DbContext
    {
        public virtual DbSet<TopicsModel> Topics { get; set; }     
        public SIContext(DbContextOptions<SIContext> options) : base(options)
        {

        }      
    }
}

It works well on .net5 with EFCORE 5.0.10 and Pomelo.EntityFrameworkCore.MySql 5.0.2.

However, after I upgrade to.net6 RC with EFCORE 6 RC and Pomelo.EntityFrameworkCore.MySql Preview6. It reports this error:

System.TypeLoadException
  HResult=0x80131522
  Message=Method 'GetServiceProviderHashCode' in type 'ExtensionInfo' from assembly 'Pomelo.EntityFrameworkCore.MySql, Version=6.0.0.0, Culture=neutral, PublicKeyToken=2cc498582444921b' does not have an implementation.
  Source=Pomelo.EntityFrameworkCore.MySql
  StackTrace:
   at Pomelo.EntityFrameworkCore.MySql.Infrastructure.Internal.MySqlOptionsExtension.get_Info()
   at Microsoft.EntityFrameworkCore.DbContextOptions.GetHashCode()
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)
   at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
   at SIComponent.Database.SIContext..ctor(DbContextOptions`1 options) in D:\Sample\SIComponent\Database\SIContext.cs:line 30
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   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 callSite, 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__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass7_0.<CreateActivator>b__0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()

What's wrong with this and how can I solve this? Thank you.

@mguinness
Copy link
Collaborator

See #1413 (comment) and try the nightly builds.

@lauxjpn
Copy link
Collaborator

lauxjpn commented Oct 6, 2021

A compatible nightly build should be up by tomorrow. The actual upgrade is already done, I am just fixing and adjusting the tests for the different server versions.

@FrantisekSidak
Copy link

Testing with nuget in version 6.0.0-preview.7.ci.20211007023054 I am getting the same exception.

I am using context with abstraction:

// configuration
services.AddDbContext<IDataContext, MySqlDataContext>(
    options => options.UseMySql(connectionString, new MySqlServerVersion(new Version(8, 0, 26)))
);

// context
public class MySqlDataContext : DbContext, IDataContext
{
    public MySqlDataContext(DbContextOptions<MySqlDataContext> options)
            : base(options)
    {
    }
}

@lauxjpn
Copy link
Collaborator

lauxjpn commented Oct 7, 2021

Testing with nuget in version 6.0.0-preview.7.ci.20211007023054 I am getting the same exception.

@FrantisekSidak See my previous comment:

A compatible nightly build should be up by tomorrow. The actual upgrade is already done, I am just fixing and adjusting the tests for the different server versions.

The PR that makes it work is #1531. Once we have merged it (probably later today), it should work.

@lauxjpn lauxjpn changed the title Errors in .net6 RC Error when using Pomelo 6.0 Preview 6/7 together with EF Core 6.0 RC1 Oct 7, 2021
@FrantisekSidak
Copy link

@FrantisekSidak See my previous comment:

Ok. I read your comment carefully, but by dates it seemed new version should be out already. Thank you for details.

@lauxjpn
Copy link
Collaborator

lauxjpn commented Oct 7, 2021

@FrantisekSidak No, sometime today (we are publishing 6.0.0-preview.7 at this very moment).

The nightly build compatible with EF Core 6.0 RC1 should have the format 6.0.0-rc.1.ci.yyyyMMddHHmmss.
Should be up in about an hour or so.

@lauxjpn
Copy link
Collaborator

lauxjpn commented Oct 7, 2021

Prerelease 6.0.0-rc.1.ci.20211007223757+sha.e5110ec is now available on our nightly build feed.
See #1413 for future updates.

@FrantisekSidak
Copy link

It works now. Thank you!

@duckwaffle
Copy link

I'm still getting this exception even when using the nightly build.

Version of Pomelo.EntityFrameworkCore.MySql: 6.0.0-rc.1.ci.20211007223757
Version of Microsoft.EntityFrameworkCore: 6.0.0-rc.2.21480.5

Exception:

System.TypeLoadException: Method 'GetServiceProviderHashCode' in type 'ExtensionInfo' from assembly 'Pomelo.EntityFrameworkCore.MySql, Version=6.0.0.0, Culture=neutral, PublicKeyToken=2cc498582444921b' does not have an implementation.
         at Pomelo.EntityFrameworkCore.MySql.Infrastructure.Internal.MySqlOptionsExtension.get_Info()
         at Microsoft.EntityFrameworkCore.DbContextOptions.GetHashCode()
         at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
         at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)
         at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
         at AltaiCasting.Db.Contexts.AltaiCastingContext..ctor(DbContextOptions`1 options) in C:\Work\AltaiCastingApi\AltaiCasting.Db\Contexts\AltaiCastingContext.cs:line 15
         at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
         at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
         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 callSite, 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__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
         at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
         at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
         at lambda_method2(Closure , IServiceProvider , Object[] )
         at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass7_0.<CreateActivator>b__0(ControllerContext controllerContext)
         at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
         at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

@lauxjpn
Copy link
Collaborator

lauxjpn commented Oct 28, 2021

@duckwaffle Do you also get an exception when using the Pomelo RC1 nightly build with the EF Core RC1 release?

The only change regarding the GetServiceProviderHashCode method was done upstream in EF Core for RC1 (which changed the return type).

So this issue should not appear with Pomelo 6.0.0-rc.1 and EF Core 6.0.0-rc.1.

You should make absolutely sure, that you are using the expected versions (check the versions of the actual DLL files in the folder you are running your app from).

@duckwaffle
Copy link

@lauxjpn thanks for that clarification, I was using the RC2 version of EFCore it turns out, not the RC1 version.

Downgrading to RC1 EFCore fixed the issue for me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants