how to find missing dependencies?

Vote:
 

Last week I installed the latest visual studio (community), and the episerver plugin.

For good measure, I also installed the "nuget" thing  https://  nuget.episerver.com/  feed/packages.svc/  (link broken up because this forum gives "server error" if you include links)

There are a lot of code examples for epi, but the majority are missing the vital information needed to compile the code.

  e.g. this line.

    using (UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(new ApplicationDbContext<ApplicationUser>("EPiServerDB")))

Vistual studio syas "The type or namespace "ApplicationUser" could not be find as you are missing a using directive or assembly reference"?

How does one resolve this?  Googling "EPiServer ApplicatoinUser" does not result in any hits. I was hoping to find some documenation for this package, with instructions on how to include it.

Are there steps I can use to locate all of the varoius missing pieces?

#209332
Nov 14, 2019 9:22
Vote:
 

Are you 100% sure you've followed https://world.episerver.com/documentation/Items/Installation-Instructions/Installing-Episerver-updates/#epifeed for setting up the nuget feeds correctly.

Once you've done this you need to click on the solution and choose restore nuget packages which should bring the episerver packages contained the ApplicationUser down. I'm not sure why you're having problems with links or editing posts, there's not usually an issue.

#209333
Nov 14, 2019 9:47
Vote:
 

Thanks Scott. Yes, I am 100% I have stup the netget stuff as per that link.  If I do "restore newget packages" I get

"All packages are already installed and there is nothing to restore."

But vs cant resolve many packages, including "ApplicationUser", "UserStore", "IPsswordHasher" etc.  How do I resolve these?

Shame this forum doesnt support uploading images.

Note, I have done steps 1 to 4 under the section:  "Adding the Episerver NuGet feed".

I also shut down VS and created a new empty episever project from scratch.  Same problem.

In desperation, I started going through the 100 or so packages and manually installing them thusly:

PM> Install-Package EPiServer.CMS.UI.AspNetIdentity

But as yet have not hit anything which can resolve these dependecies.

#209334
Edited, Nov 14, 2019 10:00
Vote:
 

This forum wont let me edit the last post (Says "unable to edit post" in pinkwhen I try to submit), so creating a new post:

In VS, there is a visual "NuGet - Solution" window, which has "browse, Installed, Updates  and Consolidate".  If i select "Episerver" under "Package source" I also see hundreds of packages, such as "ABTestingCriterion by CriteriaPack Project".  However, I dont know if any of these will have the missing dependencies?

#209380
Nov 14, 2019 10:05
Vote:
 

If it helps, if I do "manage nuget packages for solution", under the intsalled tab are the following:

1) EPiSerer.CMS, .CMS.AspNet, .CMS.Core, .CMS.TinyMce, .CMS.UI, .CMS.UI.AspNetIdentity, .CMS.UI.Core, .Framework, .Framework.Asp.Net, ServiceLocation.StructuredMap 

2) a whole bunch of non episerver stuff.

#209381
Nov 14, 2019 10:11
Vote:
 

Note also, that I dont know what to put under "using".  I have randomly put every using in every example I can find, e.g. 

using System.Configuration.Provider;
using System.Web.Security;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.Logging.Compatibility;
using EPiServer.ApplicationModules.Security;
using System.ComponentModel.DataAnnotations;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;

etc.

Of these, the only ones not greyed out are Framework and Framework.Initialization.

I dont know if the problem is I dont know how to find the right "using" location for a given namespace (such as AppliatoinUser), or that I dont have the right dependencies installed. 

I cant find any documentation which links a given object (such as ApplicationUser) with the given "using" statement with some sort of external dependency or library provding that code.

#209382
Edited, Nov 14, 2019 10:16
Vote:
 

FYI, below is the code which cant find the dependencies (to try to create a user as I cant login)

cant find ApplicationUser, UserStore<>, IPaswordHasher, ApplicationDBContext, PasswordHasher, IList etc.

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class EpiserverInitialization : IInitializableModule
{
    private static readonly string[] _roles = { "WebAdmins", "WebEditors" };

    public void Initialize(InitializationEngine context)
    {
        using (UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(new ApplicationDbContext<ApplicationUser>("EPiServerDB")))
        {
            //If there's already a user, then we don't need a seed
            if (!store.Users.Any(x => x.UserName == "sysadmin"))
            {
                var createdUser = CreateUser(store, "sysadmin", "p@ssword", "sysadmin@mysite.com");
                AddUserToRoles(store, createdUser, _roles);
                store.UpdateAsync(createdUser).GetAwaiter().GetResult();
            }
        }
    }

    private ApplicationUser CreateUser(UserStore<ApplicationUser> store, string username, string password, string email)
    {
        //We know that this Password hasher is used as it's configured
        IPasswordHasher hasher = new PasswordHasher();
        string passwordHash = hasher.HashPassword(password);

        ApplicationUser applicationUser = new ApplicationUser
        {
            Email = email,
            EmailConfirmed = true,
            LockoutEnabled = true,
            IsApproved = true,
            UserName = username,
            PasswordHash = passwordHash,
            SecurityStamp = Guid.NewGuid().ToString()
        };

        store.CreateAsync(applicationUser).GetAwaiter().GetResult();

        //Get the user associated with our username
        ApplicationUser createdUser = store.FindByNameAsync(username).GetAwaiter().GetResult();
        return createdUser;
    }

    private void AddUserToRoles(UserStore<ApplicationUser> store, ApplicationUser user, string[] roles)
    {
        IUserRoleStore<ApplicationUser, string> userRoleStore = store;
        using (var roleStore = new RoleStore<IdentityRole>(new ApplicationDbContext<ApplicationUser>("EPiServerDB")))
        {
            IList<string> userRoles = userRoleStore.GetRolesAsync(user).GetAwaiter().GetResult();
            foreach (string roleName in roles)
            {
                if (roleStore.FindByNameAsync(roleName).GetAwaiter().GetResult() == null)
                {
                    roleStore.CreateAsync(new IdentityRole { Name = roleName }).GetAwaiter().GetResult();
                }
                if (!userRoles.Contains(roleName))
                    userRoleStore.AddToRoleAsync(user, roleName).GetAwaiter().GetResult();
            }
        }
    }

    public void Uninitialize(InitializationEngine context)
    {
    }

    public void Preload(string[] parameters)
    {
    }
}
#209385
Edited, Nov 14, 2019 10:33
Vote:
 

ApplicationUser and ApplicationDBContext are in EPiServer.Cms.UI.AspNetIdentity.

But yes I think we should do a better job at documentating which nuget a class is from (at least if it is not obvious)

#209391
Nov 14, 2019 10:36
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.