title: UserManager doesn't initialize property when creating user
body: <p>I have an issue, when I'm creating a user, it doesn't initialize the property that is list&lt;> type - I get the following error:</p>
  
  <pre><code>An unhandled exception occurred while processing the request.
  NullReferenceException: Object reference not set to an instance of an object.
  AspNetCore.Views_Home_Index.ExecuteAsync() in Index.cshtml, line 53
  </code></pre>
  
  <p>The error appears only when I'm registered and logged in! I think that's important.</p>
  
  <p>As you can expect the line with the error is</p>
  
  <pre><code>foreach (var currencyUser in favoriteCurrency)
  </code></pre>
  
  <p>so it means that favoriteCurrency is null, but it shouldn't be.</p>
  
  <p>EDIT: Here is the full context:</p>
  
  <pre><code>@using X.PagedList.Mvc.Core;
  @using X.PagedList;
  @using X.PagedList.Mvc.Common
  @using Microsoft.AspNetCore.Identity
  @using WalutyBusinessLogic.Models
  @inject SignInManager&lt;User&gt; SignInManager
  @inject UserManager&lt;User&gt; UserManager
  @{
  ViewData["Title"] = "Home Page";
  }
  
  @{
  User applicationUser = null;
  List&lt;UserCurrency&gt; favoriteCurrency = null;
  
  if (SignInManager.IsSignedIn(User))
  {
      applicationUser = await UserManager.GetUserAsync(User);
      favoriteCurrency = applicationUser.UserFavoriteCurrencies;
  }
  
  }
  
  &lt;div class="text-center"&gt;
  &lt;h1 class="display-4"&gt;Welcome&lt;/h1&gt;
  &lt;/div&gt;
  
  
  &lt;form asp-controller="Home" asp-action="Index" method="get"&gt;
  &lt;div class="md-form mt-0"&gt;
      &lt;input name="searchString" class="form-control" type="text" value="@ViewBag.searchFilter" placeholder="Search by code" aria-label="Search"&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;table class="table"&gt;
  
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th scope="col"&gt;Currency code&lt;/th&gt;
          &lt;th scope="col"&gt;Full name&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr&gt;&lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      @foreach (var currencyInfo in ViewBag.SinglePageOfCurrencyInfo)
      {
          &lt;tr&gt;
              &lt;td&gt;@currencyInfo.Code&lt;/td&gt;
              &lt;td&gt;@currencyInfo.Name&lt;/td&gt;
              @if (SignInManager.IsSignedIn(User))
              {
                  bool isAlreadyIn = false;
  
                  foreach (var currencyUser in favoriteCurrency)
                  {
                      if (currencyInfo.Id == currencyUser.CurrencyId &amp;&amp; !isAlreadyIn)
                      {
                          isAlreadyIn = true;
                          break;
                      }
                  }
                  if (isAlreadyIn)
                  {
                      &lt;td&gt;&lt;a asp-controller="Favorites" asp-action="delete" asp-route-id="@currencyInfo.Id"&gt;Remove from Favorites&lt;/a&gt;&lt;/td&gt;
                  }
                  else
                  {
                      &lt;td&gt;&lt;a asp-controller="Favorites" asp-action="add" asp-route-id="@currencyInfo.Id"&gt;Add to Favorites&lt;/a&gt;&lt;/td&gt;
                  }
              }
          &lt;/tr&gt;
      }
  &lt;/tbody&gt;
  &lt;/table&gt;
  
  @Html.PagedListPager((IPagedList)ViewBag.SinglePageOfCurrencyInfo,
  page =&gt; Url.Action("Index", new { page = page, searchString = ViewBag.searchFilter }),
  new PagedListRenderOptions
  {
      LiElementClasses = new string[] { "page-item" },
      PageClasses = new string[] { "page-link" },
      MaximumPageNumbersToDisplay = 5,
      EllipsesFormat = ""
  })
  </code></pre>
  
  <p>Here is my registration method - scaffolded from identity, but slightly changed</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; OnPostAsync(string returnUrl = null)
  {
      returnUrl = returnUrl ?? Url.Content("~/");
      if (ModelState.IsValid)
      {
          var user = new User { UserName = Input.Email, Email = Input.Email, UserFavoriteCurrencies = new List&lt;UserCurrency&gt;()};
  
          var result = await _userManager.CreateAsync(user, Input.Password);
  
          if (result.Succeeded)
          {
              Log.Logger.Information($"User {Input.Email} has been created.");
  
              var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
              var callbackUrl = Url.Page(
                  "/Account/ConfirmEmail",
                  pageHandler: null,
                  values: new { userId = user.Id, code = code },
                  protocol: Request.Scheme);
  
              await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                  $"Please confirm your account by &lt;a href='{HtmlEncoder.Default.Encode(callbackUrl)}'&gt;clicking here&lt;/a&gt;.");
  
              await _signInManager.SignInAsync(user, isPersistent: false);
              return LocalRedirect(returnUrl);
          }
          foreach (var error in result.Errors)
          {
              ModelState.AddModelError(string.Empty, error.Description);
          }
      }
  
      // If we got this far, something failed, redisplay form
      return Page();
  }
  </code></pre>
  
  <p>as you can see in this part i'am indicating the creation:</p>
  
  <pre><code>var user = new User { UserName = Input.Email, Email = Input.Email, UserFavoriteCurrencies = new List&lt;UserCurrency&gt;()};
  </code></pre>
  
  <p>but it doesn't go through.</p>
  
  <p>Here are my classes:</p>
  
  <p>User:</p>
  
  <pre><code>public class User : IdentityUser
  {
      public virtual List&lt;UserCurrency&gt; UserFavoriteCurrencies { get; set; }
  }
  </code></pre>
  
  <p>UserCurrency:</p>
  
  <pre><code>public class UserCurrency
  {
      public int UserId { get; set; }
      public User User { get; set; }
      public int CurrencyId { get; set; }
      public Currency Currency { get; set; }
  }
  </code></pre>
  
  <p>Currency if needed:</p>
  
  <pre><code> public class Currency
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public List&lt;CurrencyRecord&gt; ListOfRecords { get; set; }
      public List&lt;UserCurrency&gt; FavoritedByUsers { get; set; }
  }
  </code></pre>
  
  <p>If user is logged in I receive mentioned error. What am I doing wrong?</p>