0

I am receiving the following error when I try to navigate to a website I have deployed to the production machine.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


[No relevant source lines]


Source File: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\application portal\b63251b4\7eccc081\App_Web_t1vvgyvo.1.cs    Line: 0

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   ASP._Page_Views_NewHire_NewEmpForm_cshtml.Execute() in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\application portal\b63251b4\7eccc081\App_Web_t1vvgyvo.1.cs:0
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +279
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +142
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +109
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +379
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +108
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +97
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +241
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

Now the basic error (Object reference not set..) is something I have encountered before. What has me stumped is the "No relevant source lines" and the fact that the Source File of the error is a temporary one.

I would greatly appreciate any suggestions as to what the issue might be.

EDITS BELOW

The View that should be loading:

   @model Application_Portal.Models.Employee


<h2> New Employee Data Information</h2>


<form class="form-horizontal" method="post" id='newHireForm' action="NewEmpForm">


    <input type="hidden" name="EmployeeID" value="@Model.EmployeeID" />

    <div class="form-group">
        <label class="control-label col-md-2">First Name: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.FirstName' /></div>
        <label class="control-label col-md-2">Last Name: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.LastName' /></div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">Full SSN: </label><div class='col-md-4'><input type='password' class='form-control' name="SSN" id="SSN" /></div>
        <label class="control-label col-md-2">Confirm SSN: </label><div class='col-md-4'><input type='password' class='form-control' id="SSNConfirm" /></div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">Date of Birth: </label><div class='col-md-4'><input type='text' class='form-control' name="DOB" /></div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">Phone: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.Phone' /></div>
        <label class="control-label col-md-2">Cell Phone: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.CellPhone' /></div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-2">Street Address: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.StreetAddress' /></div>
        <label class="control-label col-md-2">City: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.Applicant.City' /></div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">State: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.Applicant.State' /></div>
        <label class="control-label col-md-2">Zip: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.Applicant.Zip' /></div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">Marital Status: </label><div class='col-md-4'><input type='text' class='form-control' name="MaritalStatus" /></div>
        <label class="control-label col-md-2">Gender: </label><div class='col-md-4'><select class='form-control' name="Sex"><option value="M">Male</option><option value="F">Female</option></select></div>
    </div>


    <div class="form-group">
        <label class="control-label col-md-2">Race: </label><div class="col-md-4">
            <select class='form-control' name='Race'>
                <option value="White">White</option>
                <option value="Black">Black</option>
                <option value="Hispanic">Hispanic</option>
                <option value="Asian">Asian or Pacific Islander</option>
                <option value="Native">American Indian or Alaskan Native</option>
            </select>
        </div>
        <label class="control-label col-md-2">Residency: </label><div class='col-md-4'><select class='form-control' name="Residency"><option value="Citizen">Citizen or National of the United States</option><option value="Lawful Permanent Resident">Lawful Permanent Resident</option><option value='Authorized Alien'>Authorized Alien</option></select></div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-2">Alien # or Admission # (optional): </label><div class="col-md-4">
            <input type="text" class='form-control' name='AlienNumber' />
        </div>
    </div>
    <input type="submit" value="Submit" name="applicationSubmit" id="applicationSubmit" class="btn btn-primary pull-right" />

</form>

This is the controller/view combination that is giving me trouble:

    [Authorize]
    [NewHireFilter]
    public ActionResult NewEmpForm()
    {
        HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
        Int32 newHireID = Convert.ToInt32(ticket.Name);
        Employee newEmp;

        newEmp = dbContext.Employees.FirstOrDefault(e => e.EmployeeID == newHireID);

        return View(newEmp);
                }

However, this one works just fine:

       [Authorize]
    [NewHireFilter]
    public ActionResult ModuleOne()
    {
        ModuleOneViewModel vm = new ModuleOneViewModel();
        HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
        Int32 newHireID = Convert.ToInt32(ticket.Name);

        vm.newHire = dbContext.Employees.FirstOrDefault(e => e.EmployeeID == newHireID);

        return View(vm);
    }

Again, I would really appreciate any help as this is a perplexing issue to me.

Thanks.

KellyM
  • 2,472
  • 6
  • 46
  • 90
  • Warning! You appear to be storing passwords in plaintext in the database. This is a big security violation! Passwords should never be stored like that. They should be one way hashed and encrypted, and you should compare hashed forms of the password to determine validity. – mason Feb 21 '17 at 19:11
  • It looks like the exception is happening in the 'compiled version' of your view (NewHire_NewEmpForm_cshtml). Some object instance is not being set. Can you post all your cshtml? – MikeS Feb 21 '17 at 19:12
  • Certainly MikeS; I have added the chtml for the View that should be loading. Thanks! – KellyM Feb 21 '17 at 19:19
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – mason Feb 21 '17 at 21:22
  • @mason that is a great resource, but i do not think it help resolves my issue. The most relevant data I saw was to ensure that you are actually passing a model to the view. I am. Also, I have edited my code above to illustrate that a very similar Controller/View combinations works just fine. – KellyM Feb 21 '17 at 22:54
  • Not just a model, but any property you access, if you access a property of it that needs to not be null too – mason Feb 21 '17 at 23:51

0 Answers0