The type or namespace name ‘Application’ does not exist in the namespace ‘WebApplication1.Models’

Hi I am new to Net Core and I am following this tutorial from PragimTech. In extending IdentityUser Part(77) of tutorial when I create new Class for ApplicationUser in order to extend from IdentityUser I face a Compile error saying

type Application does not exist in namespace

. There are my codes to show.

ApplicationUser.cs

using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication1.Models
{
    public class ApplicationUser:IdentityUser
    {

    }
}

_ViewImports.cshtml

@using WebApplication1.Models
@using WebApplication1.ViewModels
@using Microsoft.AspNetCore.Identity

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

The ConfigureServices method in Startup.cs file

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContextPool<AppDbContext>(
            options => options.UseSqlServer(_config.GetConnectionString("EmployeeDBConnection"))
          );
        services.AddMvc(config => {
            var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
            config.Filters.Add(new AuthorizeFilter(policy));
        });
        services.AddScoped< IEmployeeRepository, SqlEmployeeRepository> ();
        services.AddIdentity<ApplicationUser, IdentityRole>(options => {
            options.Password.RequireNonAlphanumeric = false;
            options.Password.RequireUppercase = false;
            options.Password.RequiredLength = 4;
        }).
            AddEntityFrameworkStores<AppDbContext>();
    }

The injection part in _layout.cshtml

@inject SignInManager<ApplicationUser> signeInManager;

AccountController

public class AccountController : Controller
    {
        private readonly UserManager<ApplicationUser> userManager;
        private readonly SignInManager<ApplicationUser> signInManager;

        public AccountController(UserManager<ApplicationUser> userManager, 
                            SignInManager<ApplicationUser> signInManager)
        {
            this.userManager = userManager;
            this.signInManager = signInManager;
        }


        [AcceptVerbs("Post","Get")]
        [AllowAnonymous]
        public async Task< IActionResult> IsEmailInUse(string email)
        {
            var user = await userManager.FindByEmailAsync(email);

            if(user == null)
            {
                 return Json(true);
            }
            else
            {
                return Json($"Email {email} is already taken.");
              }
         }

         [HttpGet]
         [AllowAnonymous]
         public IActionResult Register()
         {
             return View();
          }

         [HttpPost]
         [AllowAnonymous]
         public async Task< IActionResult> Register(RegisterViewModel model)
         {
             if (ModelState.IsValid)
              {
                 var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                 var result = await userManager.CreateAsync(user, model.Password);
                 if (result.Succeeded)
                 {
                     await signInManager.SignInAsync(user, false);
                     return RedirectToAction("index","home");
                      }
                  else
                {
                     foreach (var error in result.Errors)
                     {
                         ModelState.AddModelError("", error.Description);
                     }
            }
        }
        return View(model);
         }

         [HttpGet]
         [AllowAnonymous]
         public IActionResult Login()
         {
             return View();
          }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var result = await signInManager.PasswordSignInAsync(model.Email, model.Password, 
               model.RememberMe, false);
              if (result.Succeeded)
              {
                   if(!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                   {
                    return Redirect(returnUrl);
                    }else 
                     return RedirectToAction("index", "home");
                 }
                 else
                 {
                     ModelState.AddModelError(string.Empty, "Invalid user or password");
                  }
              }
               return View(model);
         }

          [HttpPost]
          public async Task<IActionResult> Logout()
          {
              await signInManager.SignOutAsync();
              return RedirectToAction("Index", "home");
           }

             }

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Just Cleaned the solution and re-built it.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x