找不到方法:'System.Reflection.MethodInfo Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.get_SelectAsyncMethod()'

Fra*_*qui 19 entity-framework-core .net-core identityserver4

我需要帮助的人我正在一个新的项目中,我正在实现身份服务器4,我正在尝试使用我的数据库中的asp.Identity来恢复以前创建的用户,以便能够验证我何时从外部登录身份服务器4.抱歉我的英文.我的Startup.cs

public class Startup
{    

public IConfiguration Configuration { get; }

public Startup(IConfiguration configuration)
{
    Configuration = configuration;
}

 public void ConfigureServices(IServiceCollection services)
{
    #region --Identity ASP

    services.AddDbContext<QGoodDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")),ServiceLifetime.Transient);
    services.AddIdentity<ApplicationUser, ApplicationRole>()
            .AddEntityFrameworkStores<QGoodDbContext>()                   
            .AddDefaultTokenProviders();

    #endregion

    services.AddMvc();

    services.AddScoped<UserManager<ApplicationUser>>();
    services.AddScoped<SignInManager<ApplicationUser>>();

    // configure identity server with in-memory stores, keys, clients and scopes
    services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryPersistedGrants()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients());
            //.AddAspNetIdentity<ApplicationUser>();
        }
}
Run Code Online (Sandbox Code Playgroud)

当我初始化我的数据库时,我已经有这个错误

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {          

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseIdentityServer();
            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();
            InitializeDatabase(app);
        }

        private void InitializeDatabase(IApplicationBuilder app)
        {
            using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
            {
                //serviceScope.ServiceProvider.GetRequiredService<QGoodDbContext>().Database.Migrate();

                var context = serviceScope.ServiceProvider.GetRequiredService<QGoodDbContext>();

            }
        }
Run Code Online (Sandbox Code Playgroud)

在我AccountController打电话时我有例外 await _userManager.FindByLoginAsync(provider, providerUserId);

 public class AccountController : Controller
    {
        private readonly UserManager<ApplicationUser> _userManager;
        private readonly SignInManager<ApplicationUser> _signInManager;
        private readonly QGoodDbContext _context;
        private readonly TestUserStore _users;
        private readonly IIdentityServerInteractionService _interaction;
        private readonly IClientStore _clientStore;
        private readonly IAuthenticationSchemeProvider _schemeProvider;
        private readonly IEventService _events;


        public AccountController(
            UserManager<ApplicationUser> userManager,
            SignInManager<ApplicationUser> signInManager,
            QGoodDbContext context,
            IIdentityServerInteractionService interaction,
            IClientStore clientStore,
            IAuthenticationSchemeProvider schemeProvider,
            IEventService events,
            TestUserStore users = null)
        {
            // if the TestUserStore is not in DI, then we'll just use the global users collection
            // this is where you would plug in your own custom identity management library (e.g. ASP.NET Identity)
            _users = users ?? new TestUserStore(TestUsers.Users);
            _userManager = userManager;
            _signInManager = signInManager;
            _context = context;
            _interaction = interaction;
            _clientStore = clientStore;
            _schemeProvider = schemeProvider;
            _events = events;
        }
          public async Task<IActionResult> ExternalLoginCallback()
        {
            try
            {
                // read external identity from the temporary cookie
                var result = await HttpContext.AuthenticateAsync(IdentityServer4.IdentityServerConstants.ExternalCookieAuthenticationScheme);
                if (result?.Succeeded != true)
                {
                    throw new Exception("External authentication error");
                }

                // lookup our user and external provider info
                var (userTest, provider, providerUserId, claims) = FindUserFromExternalProvider(result);
                var user = await _userManager.FindByLoginAsync(provider, providerUserId);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

例外情况是:

找不到方法:'System.Reflection.MethodInfo Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.get_SelectAsyncMethod()'

小智 25

你好,你能展示你的包安装吗?当我使用EFCore时,我也遇到同样的问题.我安装包时解决了这个问题

Microsoft.EntityFrameworkCore.Relational
Run Code Online (Sandbox Code Playgroud)

  • 降级EF核心工具不起作用.Microsoft.EntityFrameworkCore.Relational做了这件事! (3认同)

Gra*_*cie 7

有迹象表明,表现出的行为这一问题的若干变化MissingMethodException,NotImplemementedException或MissingFieldException。

看来这些是由Microsoft.EntityFrameworkCore名称空间内的版本冲突引起的。例如,此错误可能是由于在同一程序集中引用Microsoft.EntityFrameworkCore.InMemory2.2.0和Microsoft.EntityFrameworkCore.Relational2.1.4 引起的。

解决方案是协调nuget软件包引用的版本,以便它们在内部不引用EF Core组件的不同版本。


Ali*_*efi 6

我不知道真正的问题是什么,但是在将Microsoft.EntityFrameworkCore.Tools降级到2.1.4版本并再次升级到最新版本后,问题就消失了。