C# &引用;发现不同版本之间存在冲突”;或System.MissingMethodException(当使用aspnetcore.identity时)
我被这个依赖性问题所困扰 我的设置:C# &引用;发现不同版本之间存在冲突”;或System.MissingMethodException(当使用aspnetcore.identity时),c#,asp.net-core,asp.net-identity,C#,Asp.net Core,Asp.net Identity,我被这个依赖性问题所困扰 我的设置: 具有aspnetcore.identity代码的.Net标准库(UserManager, IdentityUser等)+所有需要的扩展包,如 版本2.2.0(不是3.x.x)中的Microsoft.Extensions.Identity.Stores 数据库已迁移到aspnetcore.identity布局 .NET 4.7.2应使用.NET标准DLL的WebForms GUI 现在我想使用以下代码访问WebForms应用程序中的用户: using Syst
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyNetStandard20LibraryWithTheIdentityClasses;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace WebApplication2
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
var userStore = new UserStore<ApplicationUser, ApplicationRole, ApplicationDbContext, Guid>(
new ApplicationDbContext(optionsBuilder.Options)
);
AspNetUserManager<ApplicationUser> userManager = new AspNetUserManager<ApplicationUser>(
userStore,
null,
new PasswordHasher<ApplicationUser>(),
new List<UserValidator<ApplicationUser>>() { new UserValidator<ApplicationUser>() },
null,
null,
null,
null,
null
);
var x = userManager.Users; // Exception!
}
}
}
使用System.Collections.Generic;
使用系统配置;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用MyNetstandard20 Library及其Identity类;
使用Microsoft.AspNetCore.Identity;
使用Microsoft.AspNetCore.Identity.EntityFrameworkCore;
使用Microsoft.EntityFrameworkCore;
命名空间WebApplication2
{
公共部分类\u默认值:第页
{
受保护的无效页面加载(对象发送方、事件参数e)
{
var optionsBuilder=new DbContextOptionsBuilder
我不知道如何解决这个问题。我需要将我的库保持在.Net标准,将Webforms应用程序保持在.Net Framework 4.7
我无法使用的解决方案…
安装Microsoft.AspNetCore.Identity的3.x。我无法这样做,因为它与.Net 4.7.2不兼容(nuget不会安装它…)
更新
我在这里发布了一个具体案例中的一个问题:因此,我有一个解决问题的方法:
使用Microsoft.EntityFrameworkCore.SqlServer版本2.2.6(不是3.1.1,尽管它应该与.net标准2.0一起使用…)
删除nuget软件包、清除nuget缓存、删除本地计算机上的nuget软件包(在C://../Users/../nuget文件夹中)、将nuget管理格式更改为“PackageReference”、重新安装所有内容并处理有帮助的警告(我无法确切说明版本冲突的问题)
请参阅以了解更多信息可能不是问题的一部分,但您使用的是哪一个版本的4.7?4.7.2是第一个完全符合.Net标准2.0的完整框架版本,没有附加依赖项。嘿,是的,WebForms应用程序的版本将通过所有*.csproj
检查所有
指向完全相同的文件和版本。执行dotnet清理
并删除任何obj'
和bin
文件夹。也可以删除整个NuGet缓存,以防万一。再试一次。@FrankNielsen我清理了缓存并清理了整个解决方案。在我的小示例中,引用具有相同的版本。但我仍然得到了“System.MissingMethodException”当我使用UserManager时(异常在ApplicationDbContext.OnModelCreating中引发),您的应用程序是多个项目的组合吗?我的观点是,如果两个依赖的项目都有此引用
(一个用于.net标准,另一个用于.net framework)。那么您的目标是(exe)除非您确保您的目标项目也具有正确的
,否则项目可以正确地结束。