“不同版本之间发现冲突".使用aspnetcore.identity时出现System.MissingMethodException [英] "Found conflicts between different versions" OR System.MissingMethodException when using aspnetcore.identity
问题描述
我陷入了这个依赖性问题 ...
i'm am stuck with this dependency problem...
我的设置:
-
.net标准库,带有aspnetcore.identity代码(UserManager, IdentityUser等)+所有必需的扩展包,例如 Microsoft.Extensions.Identity.Stores in version 2.2.0(非3.x.x)
.Net Standard libraries with aspnetcore.identity code (UserManager, IdentityUser, etc) + all needed extension packages like Microsoft.Extensions.Identity.Stores in version 2.2.0 (not 3.x.x)
数据库已经迁移到aspnetcore.identity布局
Database is already migrated to aspnetcore.identity layout
现在,我要使用以下代码访问WebForms应用程序中的用户:
Now I want to access the Users in the WebForms App with this code:
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类位于单独的点网标准DLL中.
Note that the ApplicationUser Class is in a separate dot net standard DLL.
可以说"UseSqlServer()"无法正常工作,我需要安装"Microsoft.EntityFrameworkCore.SqlServer"(将"System.Data.SqlClient"安装到依赖项中).
Its fine to the point that "UseSqlServer()" is not working and I need to install "Microsoft.EntityFrameworkCore.SqlServer" (which installs "System.Data.SqlClient" die to dependency).
现在,我收到错误消息"警告MSB3277:发现无法解决的不同版本的"System.Data.SqlClient"之间的冲突."
And now I get the error "warning MSB3277: Found conflicts between different versions of "System.Data.SqlClient" that could not be resolved."
您认为我的方法有什么重大问题吗?我只想正常"使用WebForms项目中的AspNetCore.Identity表.所有的Dll都实现.Net标准2.0,我认为这应该可以,对吧?
Do you see any major problem in my approach? I just want to "normally" use the AspNetCore.Identity Tables in a WebForms Project. All Dlls implement the .Net standard 2.0 and I assume that this should be ok, right?
然后是另一个问题:如何通过不同版本之间的冲突"解决该问题.这是在一个最小的示例中完成的.如果我想在真实的WebForms应用程序中使用所有这些功能,我在安装的大多数其他软件包上都会遇到相同的错误...
Then the other Question: How do I approach the Issue with the "conflicts between different versions". This is done in a minimal example. If I want to use all of this in the real WebForms application I get same error on most additional packages I install...
更新: 如果我将扩展程序包更新到3.1.1,则上述问题已解决,但执行代码后出现此错误:正确
Update: If I update the extension packages to 3.1.1 this issue above is solved but then I execute the code I get this error: right
System.MissingMethodException
HResult = 0x80131513
消息=方法:"Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder 1.HasIndex(System.Linq.Expressions.Expression
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>)".
Source=
StackTrace:
我发现了这一点: https://github.com/dotnet/aspnetcore/issues/8467
我不确定该如何解决.我需要将库保留为.Net Standard,将Webforms应用程序保留为.Net Framework 4.7.
I'm not sure how to solve this. I need to keep my libraries to .Net Standard and the Webforms application to .Net Framework 4.7.
我无法使用的解决方案... 安装3.x的Microsoft.AspNetCore.Identity.我不能这样做,因为它与.Net 4.7.2不兼容(nuget不会安装它...) https://github.com/dotnet/aspnetcore/issues/11021
A Solution that I cannot use... Install 3.x of Microsoft.AspNetCore.Identity. I cannot do that because its not compatible with .Net 4.7.2 (nuget won't install it...) https://github.com/dotnet/aspnetcore/issues/11021
更新 我在特定情况下在此处发布了一个问题: ApplicationDbContext. .Net Standard 2.0中的OnModelCreating()具有MissingMethodException
Update I posted one of the issues in a specific case here: ApplicationDbContext.OnModelCreating() in .Net Standard 2.0 has MissingMethodException
推荐答案
因此,我有一个解决问题的方法:
So, I have a solution for my problem:
使用Microsoft.EntityFrameworkCore.SqlServer版本2.2.6(即使它应与.net标准2.0兼容,也不要3.1.1)
use Microsoft.EntityFrameworkCore.SqlServer version 2.2.6 (NOT 3.1.1 even though its supposed to work with .net standard 2.0...)
以及一系列删除nuget软件包,清除nuget缓存,删除本地计算机上的nuget软件包(在C:/../Users/.../.nuget文件夹中),将nuget管理格式更改为"PackageReference"的顺序",重新安装所有内容并处理警告有帮助(我无法说出与版本冲突有关的确切问题)
And a sequence of deleting nuget packages, clearing nuget cache, deleting nuget packages on the local computer (in the C:/../Users/.../.nuget folder), changing the nuget management format to "PackageReference", reinstalling everything and dealing with warnings helped (I cant say what exactly the issue was regarding the version-conflicts)
请参阅.Net Standard 2.0中的 ApplicationDbContext.OnModelCreating()有MissingMethodException 以获得更多信息
See ApplicationDbContext.OnModelCreating() in .Net Standard 2.0 has MissingMethodException for more information
这篇关于“不同版本之间发现冲突".使用aspnetcore.identity时出现System.MissingMethodException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!