“Found conflicts between different versions” OR System.MissingMethodException when using aspnetcore.identity

核能气质少年 提交于 2020-02-06 08:01:06

问题


i'm am stuck with this dependency problem...

My Setup:

  1. .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)

  2. Database is already migrated to aspnetcore.identity layout

  3. .NET 4.7.2 WebForms GUI that is supposed to use the .Net Standard Dlls

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!
        }
    }
}

Note that the ApplicationUser Class is in a separate dot net standard DLL.

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).

And now I get the error "warning MSB3277: Found conflicts between different versions of "System.Data.SqlClient" that could not be resolved."

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?

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...

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 Message=Methode nicht gefunden: "Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder1.HasIndex(System.Linq.Expressions.Expression1>)". Source= StackTrace:

I found this: https://github.com/dotnet/aspnetcore/issues/8467

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.

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

Update I posted one of the issues in a specific case here: ApplicationDbContext.OnModelCreating() in .Net Standard 2.0 has MissingMethodException


回答1:


So, I have a solution for my problem:

use Microsoft.EntityFrameworkCore.SqlServer version 2.2.6 (NOT 3.1.1 even though its supposed to work with .net standard 2.0...)

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)

See ApplicationDbContext.OnModelCreating() in .Net Standard 2.0 has MissingMethodException for more information



来源:https://stackoverflow.com/questions/59971536/found-conflicts-between-different-versions-or-system-missingmethodexception-wh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!