.net core 未找到方法:';System.Reflection.MethodInfo Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.get_SelectAsyncMethod()';
我需要帮助的人我正在一个新的项目中,我正在实施identity server 4,我正在尝试使用asp.identity恢复以前创建的用户,我的数据库中有asp.identity,以便在我从identity server 4进行外部登录时能够进行验证。对不起,我的英语不好。 我的Startup.cs.net core 未找到方法:';System.Reflection.MethodInfo Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.get_SelectAsyncMethod()';,.net-core,entity-framework-core,identityserver4,.net Core,Entity Framework Core,Identityserver4,我需要帮助的人我正在一个新的项目中,我正在实施identity server 4,我正在尝试使用asp.identity恢复以前创建的用户,我的数据库中有asp.identity,以便在我从identity server 4进行外部登录时能够进行验证。对不起,我的英语不好。 我的Startup.cs public class Startup { public IConfiguration Configuration { get; } public Startup(IConfigura
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>();
}
}
例外情况是:
找不到方法:“System.Reflection.MethodInfo Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.get\u SelectAsyncMethod()”
嗨,你能展示你的安装包吗?当我使用EFCore时,我也有同样的问题。我在安装软件包时解决了这个问题
Microsoft.EntityFrameworkCore.Relational >= 2.2.0
我不知道真正的问题是什么,但在将Microsoft.EntityFrameworkCore.Tools降级到2.1.4版并再次升级到上一个版本后,问题消失了。此问题的几个变体表现出
MissingMethodException
的行为,NotImplementedException
或MissingFieldException
这些问题似乎是由Microsoft.EntityFrameworkCore命名空间中的版本冲突引起的。例如,在同一程序集中引用Microsoft.EntityFrameworkCore.InMemory
2.2.0和Microsoft.EntityFrameworkCore.Relational
2.1.4可能会导致此错误
解决方案是协调nuget包引用的版本,以便它们不会在内部引用不同版本的EF Core组件。我在.Net Core 2.2版本的AWS Lambda上实施项目时遇到了这个问题-我做了两件事来修复它:
我怀疑是第二个操作修复了它。感谢您的评论,感谢您的帮助,即您实际使用了entity framework 6,还是只是添加了标记?降级EF core工具不起作用。Microsoft.EntityFrameworkCore.Relational完成了该契约!当升级EF Core时,别忘了升级数据库提供程序。刚刚经历了这个问题的痛苦,才发现我已经对这个答案投了赞成票,并且喜欢这个问题。lol。效果很好。奇怪,默认情况下不包括此项。改进建议:Microsoft.EntityFrameworkCore.Relational必须大于等于2.2.0。我将我的错误添加到了较低版本,但这并不能解决问题。当我尝试使用2.2.0时,它立即起到了作用。值得一提的是,一些第三方库(如Devart)具有内部引用,必须对其进行协调。
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);
}
}
}
Microsoft.EntityFrameworkCore.Relational >= 2.2.0