title: ExceptionHandlerMiddleware|An unhandled exception has occurred: Object reference not set to an instance of an object
body: <p>I have seen this issue in other posts, but I believe my situation may be different. My code works fine on localhost, but errors when I deploy to the web server. Using ASP.NET Core 2.0 and SQL Server 2012. I believe it has to do with my <code>UserType</code> class (<code>Model.LoggedInUserType</code>):</p>
  <pre><code>public string GetUserType(string LoginID)
  {
       string user = ClaimsPrincipal.Current.Identity.Name;
  
       Employee employee = db.tblEmployee.FirstOrDefault(e =&gt; (e.FirstName + '.' + e.LastName) == user);
       string userType = employee.UserType;
  
       return userType;
  }
  </code></pre>
  <p>UserTypeViewModel.cs</p>
  <pre><code>public string LoggedInUserType = BaseInfoClass.UserType;
  </code></pre>
  <p>Error (from log):</p>
  <blockquote>
  <p>2018-09-12
  16:06:04.9272|2|INFO|Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker|Executed
  action
  ApostilleDNCv2.Controllers.TransactionController.UpdateTransaction
  (ApostilleDNCv2) in 906.2122ms  2018-09-12
  16:06:04.9272|3|INFO|Microsoft.AspNetCore.Session.DistributedSession|Session started; Key:68a158b8-c8bb-9d16-6e66-8c1a3942f3be,
  Id:9c7a85af-15d4-b8c1-1286-c0ca515cb1e2  2018-09-12
  16:06:04.9433||ERROR|Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware|An
  unhandled exception has occurred: Object reference not set to an
  instance of an object. System.NullReferenceException: Object reference
  not set to an instance of an object.    at
  AspNetCore._Views_Shared_Components_Apostille_default_cshtml.d__22.MoveNext()
  in
  C:\TFS\Corporations\Development\Src\ApostilleDNCv2\ApostilleDNCv2\Views\Shared\Components\Apostille\default.cshtml:line
  42
  --- End of stack trace from previous location where exception was thrown ---</p>
  </blockquote>
  <p>View (UpdateTransactionPost.cshtml) code:</p>
  <pre><code>&lt;div class=&quot;col-lg-offset-2&quot;&gt;
          @await Component.InvokeAsync(&quot;Apostille&quot;, new { tid = Model.Trans.TransactionID })
  &lt;/div&gt;
  &lt;div class=&quot;col-lg-offset-2&quot;&gt;
          @await Component.InvokeAsync(&quot;Certificate&quot;, new { tid = Model.Trans.TransactionID })
  &lt;/div&gt;
  </code></pre>
  <p>View Component (Shared\Components\Apostille\default.cshtml - Line: 42):</p>
  <pre><code>&lt;th class=&quot;txtctr&quot; style=&quot;@(Model.LoggedInUserType.ToString() != &quot;ADM&quot; ? &quot;display:none&quot; : &quot;&quot; )&quot;&gt;
                      @Html.DisplayName(&quot;Delete&quot;)
  &lt;/th&gt;
  </code></pre>
  <p>The purpose of the style reference is so that the delete (and certain other functions) are only visible/available to admins.</p>
  <p>This web page displays a 400 error.  Other pages that do not rely on UserType display fine.</p>
  <p>My questions: why does this work locally, but not from the web server?  How can I correct this issue, (hopefully) without rewriting the whole authentication scheme?</p>