How to know which line give me error incorrect string with date time

Ahmed Salah Abed Elaziz 390 Reputation points
2023-11-07T20:26:17.46+00:00

I work on app asp.net MVC . I face issue on local machine code below working without any issue but on IIS server publish I get error 500 internal server error

I get error Input string was not in a correct format with Date Time

my question which line date time conversation make this error and which fuction or convert there are multiple one

so How to know this error

I don't know error because i work on server iis

so which tool or modifications code that let me know source line of error .

can you please help me

How to know which line give error incorrect string with date time

    [HttpPost]
    public JsonResult RequesterIndex(ResignationRequester resignationRequester)
    {
        dynamic responseData = new ExpandoObject();
        responseData.success = false;
        responseData.message = "";
       
        var filenumber = resignationRequester.EmpID;
        if (Session[SessionKeys.UserCode] != null)
        {
            JDEUtility jde = new JDEUtility();
            resignationRequester.DeptCode = Session[SessionKeys.DepartmentCode].ToString();
            resignationRequester.EmpID = Convert.ToInt32(Session[SessionKeys.UserCode]);
            resignationRequester.EmpName = Convert.ToString(Session[SessionKeys.Username]);
            resignationRequester.Dept = Convert.ToString(Session[SessionKeys.Department]);
            resignationRequester.Designation = Convert.ToString(Session[SessionKeys.Designation]);
            resignationRequester.PayGrade = Convert.ToString(Session[SessionKeys.PayGrade]);
            resignationRequester.CompanyCode = Convert.ToString(Session[SessionKeys.Company]);
            resignationRequester.Gender = Convert.ToString(Session[SessionKeys.Gender]);

            resignationRequester.ServiceDuration = Convert.ToString(Session[SessionKeys.ServiceDuration]);
            int noticeperiod = Convert.ToInt32(Session[SessionKeys.NoticePeriod]);
            int julianRequestDate = JulianDate.DateTimeToJulian(resignationRequester.LastWorkingDate);
            int SubmitionDate = JulianDate.DateTimeToJulian((DateTime)Session[SessionKeys.SubmitionDate]);
            int JoinedDate = JulianDate.DateTimeToJulian((DateTime)Session[SessionKeys.JoinDate]);
            int storedLastedWorkingDate = JulianDate.DateTimeToJulian((DateTime)Session[SessionKeys.LastWorkingDate]);
            int visaExpiryDate;
            if (Session[SessionKeys.VisaExpiryDate] == null)
            {
                visaExpiryDate = 0;
            }
            else
            {
                DateTime visDateExpire = Convert.ToDateTime(Session[SessionKeys.VisaExpiryDate]);
                visaExpiryDate = JulianDate.DateTimeToJulian(visDateExpire);

            }


         

            if (ModelState.IsValid)
            {
             

                if (julianRequestDate > storedLastedWorkingDate)
                {
                    //ViewBag.errorMsg
                    responseData.success = false;
                    responseData.message = "Last Working Date Must Not Increase Notice Period";
                    return Json(responseData);
                 

                }
                if (resignationRequester.DirectManager == 0)
                {
                 
                    responseData.success = false;
                    responseData.message = "Department Manager Must Be Bigger Than 0";
                    return Json(responseData);
                   

                }
                if (Convert.ToString(resignationRequester.LineManager).Length < 6 && !string.IsNullOrEmpty(resignationRequester.LineManager.ToString()))
                {
                    responseData.success = false;
                    responseData.message = "Length Line Manager Must Be equal 6 or More";
                    return Json(responseData);
                 
                }
                if (Convert.ToString(resignationRequester.DirectManager).Length < 6 && !string.IsNullOrEmpty(resignationRequester.DirectManager.ToString()))
                {
                    responseData.success = false;
                    responseData.message = "Length Direct Manager Must Be equal 6 or More";
                    return Json(responseData);
                   
                }
                if (Convert.ToInt32(resignationRequester.EmpID) == Convert.ToInt32(resignationRequester.DirectManager) &&
Convert.ToInt32(resignationRequester.EmpID) == Convert.ToInt32(resignationRequester.LineManager)
&& !string.IsNullOrEmpty(Convert.ToString(resignationRequester.LineManager)) && !string.IsNullOrEmpty(Convert.ToString(resignationRequester.DirectManager)))
                {
                    responseData.success = false;
                    responseData.message = "Requester Have Same Number of Manager";
                    return Json(responseData);
                  
                }
                if (!string.IsNullOrEmpty(Convert.ToString(resignationRequester.LineManager)) && resignationRequester.LineManagerName == null)
                {
                    responseData.success = false;
                    responseData.message = "Line Manager Name Blank";
                    return Json(responseData);
                    //goto InvalidModel;
                }
                if (julianRequestDate > 0 && SubmitionDate > 0 && julianRequestDate < SubmitionDate)
                {
                    responseData.success = false;
                    responseData.message = "Last Worked Date Must be Bigger than Submit Date";
                    return Json(responseData);
                    //goto InvalidModel;
                }
    

                int checkEmployeeNoExist = jde.CheckEmployeeExistOrNot(resignationRequester.EmpID);
                if (checkEmployeeNoExist >= 1)
                {
                    responseData.success = false;
                    responseData.message = "Employee Exist Before";
                    return Json(responseData);
    
                }


                try
                {
                    Workforce.InsertToReignation(resignationRequester, JoinedDate, (string)Session[SessionKeys.Username], (DateTime)Session[SessionKeys.LastWorkingDate], noticeperiod, (int)Session[SessionKeys.UserCode]);
                }
                catch (Exception ex)
                {
                    responseData.success = false;
                    responseData.message = "Create Not Done Correctly";
                    return Json(responseData);
                }
                Session[SessionKeys.DirectManager] = GetEmployeeName(Convert.ToString(resignationRequester.DirectManager));
                Session[SessionKeys.LineManager] = GetEmployeeName(Convert.ToString(resignationRequester.LineManager));
                if (string.IsNullOrEmpty(ViewBag.errorMsg))
                {
                    responseData.success = true;
                    responseData.message = "Resignation Submission form Created successfully";
                    TempData["SuccessBeforePrint"] = 1;

                    return Json(responseData);
                }



            }
            else
            {
                responseData.success = false;
                var errors = ModelState.Select(x => x.Value.Errors)
                                        .Where(y => y.Count > 0)
                                        .ToList();
                responseData.message = "Some Required Fields Not Added";
                return Json(responseData);

            }
        }
        else
        {
            responseData.success = false;
            responseData.message = "No Data For This File No";
            return Json(responseData);
        }
        return Json(responseData);
        
    }
Windows development | Internet Information Services
Developer technologies | ASP.NET | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Olaf Helper 47,516 Reputation points
    2023-11-08T10:30:19.79+00:00

    In one part you handle "VisaExpiryDate" as integer and in the next as datetime; that can't work,


  2. Bruce (SqlWork.com) 78,086 Reputation points Volunteer Moderator
    2023-11-12T02:00:16.8366667+00:00

    While the best approach is proper logging so you can reproduce the problem locally, just push a debug build and pdb file.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.