"Found conflicts between different versions" 或 System.MissingMethodException 当使用 aspnetcore.identity
"Found conflicts between different versions" OR System.MissingMethodException when using aspnetcore.identity
我被这个依赖性问题困住了...
我的设置:
.Net 标准库,带有 aspnetcore.identity 代码(UserManager,
IdentityUser 等)+ 所有需要的扩展包,如
Microsoft.Extensions.Identity.Stores 版本 2.2.0(不是 3.x.x)
数据库已经迁移到 aspnetcore.identity 布局
- .NET 4.7.2 应该使用 .Net 标准 Dll 的 WebForms GUI
现在我想使用以下代码访问 WebForms 应用程序中的用户:
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!
}
}
}
请注意,ApplicationUser Class 位于单独的点网标准 DLL 中。
很好,以至于 "UseSqlServer()" 无法正常工作,我需要安装 "Microsoft.EntityFrameworkCore.SqlServer"(安装 "System.Data.SqlClient" 死于依赖)。
现在我收到错误消息“warning MSB3277:发现不同版本的 "System.Data.SqlClient" 之间存在无法解决的冲突。”
您认为我的方法有什么大问题吗?我只想 "normally" 在 WebForms 项目中使用 AspNetCore.Identity 表。所有 Dll 都实现了 .Net 标准 2.0,我认为这应该没问题,对吧?
然后是另一个问题:如何解决 "conflicts between different versions" 的问题。这是在一个最小的例子中完成的。如果我想在真正的 WebForms 应用程序中使用所有这些,我在安装的大多数附加包中都会遇到相同的错误...
更新:
如果我将扩展包更新到 3.1.1,上面的这个问题就解决了,但是当我执行代码时,我得到了这个错误:对
System.MissingMethodException
HResult=0x80131513
Message=Methode nicht gefunden:"Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder1.HasIndex(System.Linq.Expressions.Expression
1>)"。
来源=
堆栈跟踪:
我发现了这个:https://github.com/dotnet/aspnetcore/issues/8467
我不知道如何解决这个问题。我需要将我的库保留为 .Net Standard,并将 Webforms 应用程序保留为 .Net Framework 4.7。
我无法使用的解决方案...
安装 Microsoft 3.x。AspNetCore.Identity。我不能那样做,因为它与 .Net 4.7.2 不兼容(nuget 不会安装它......)
https://github.com/dotnet/aspnetcore/issues/11021
更新
我在这里发布了一个特定案例中的问题之一:
那么,我的问题有了解决方案:
使用 Microsoft.EntityFrameworkCore.SqlServer 版本 2.2.6(不是 3.1.1,尽管它应该与 .net 标准 2.0 一起工作...)
以及一系列删除nuget包,清除nuget缓存,删除本地计算机上的nuget包(在C:/../Users/.../.nuget文件夹),将nuget管理格式更改为"PackageReference",重新安装所有内容并处理警告有帮助(我不能说出关于版本冲突的确切问题)
有关详细信息,请参阅
我被这个依赖性问题困住了...
我的设置:
.Net 标准库,带有 aspnetcore.identity 代码(UserManager, IdentityUser 等)+ 所有需要的扩展包,如 Microsoft.Extensions.Identity.Stores 版本 2.2.0(不是 3.x.x)
数据库已经迁移到 aspnetcore.identity 布局
- .NET 4.7.2 应该使用 .Net 标准 Dll 的 WebForms GUI
现在我想使用以下代码访问 WebForms 应用程序中的用户:
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!
}
}
}
请注意,ApplicationUser Class 位于单独的点网标准 DLL 中。
很好,以至于 "UseSqlServer()" 无法正常工作,我需要安装 "Microsoft.EntityFrameworkCore.SqlServer"(安装 "System.Data.SqlClient" 死于依赖)。
现在我收到错误消息“warning MSB3277:发现不同版本的 "System.Data.SqlClient" 之间存在无法解决的冲突。”
您认为我的方法有什么大问题吗?我只想 "normally" 在 WebForms 项目中使用 AspNetCore.Identity 表。所有 Dll 都实现了 .Net 标准 2.0,我认为这应该没问题,对吧?
然后是另一个问题:如何解决 "conflicts between different versions" 的问题。这是在一个最小的例子中完成的。如果我想在真正的 WebForms 应用程序中使用所有这些,我在安装的大多数附加包中都会遇到相同的错误...
更新: 如果我将扩展包更新到 3.1.1,上面的这个问题就解决了,但是当我执行代码时,我得到了这个错误:对
System.MissingMethodException
HResult=0x80131513
Message=Methode nicht gefunden:"Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder1.HasIndex(System.Linq.Expressions.Expression
1>)"。
来源=
堆栈跟踪:
我发现了这个:https://github.com/dotnet/aspnetcore/issues/8467
我不知道如何解决这个问题。我需要将我的库保留为 .Net Standard,并将 Webforms 应用程序保留为 .Net Framework 4.7。
我无法使用的解决方案... 安装 Microsoft 3.x。AspNetCore.Identity。我不能那样做,因为它与 .Net 4.7.2 不兼容(nuget 不会安装它......) https://github.com/dotnet/aspnetcore/issues/11021
更新
我在这里发布了一个特定案例中的问题之一:
那么,我的问题有了解决方案:
使用 Microsoft.EntityFrameworkCore.SqlServer 版本 2.2.6(不是 3.1.1,尽管它应该与 .net 标准 2.0 一起工作...)
以及一系列删除nuget包,清除nuget缓存,删除本地计算机上的nuget包(在C:/../Users/.../.nuget文件夹),将nuget管理格式更改为"PackageReference",重新安装所有内容并处理警告有帮助(我不能说出关于版本冲突的确切问题)
有关详细信息,请参阅