Unable to evaluate expression because the code is optimized

Hi this error bugging me for days already and I don’t know why it occurred the last thing I remember was installing VS2015 in my computer and now my web application does not start anymore.

BTW this application was built in .net framework 3.5 and this is currently in the login page of the site. I can’t redirect to the homepage even if my credentials are correct and it always throw this error. Please see images below;
enter image description here
enter image description here

overloading the redirect method, Redirect(url, endresponse) does not resolve the problem, exception is not thrown but it does not redirect to my homepage after. Check code below.

try
    {
        lblErrorLogin.Text = "";
        //validate empty username and password
        if (string.IsNullOrEmpty(txtUserName.Text) || string.IsNullOrEmpty(txtPass.Text))
        {
            lblErrorLogin.Text = "Please enter username and password correctly.";
            return;
        }

        BasicFormAuthentication formAuth = new BasicFormAuthentication();
        bool isAuthenticated;

        //check if the user input is correct
        isAuthenticated = formAuth.IsAuthenticated(txtUserName.Text, txtPass.Text);

        if (isAuthenticated == true)
        {
            //if authenticated then create a user session for the username
            formAuth.CreateUserSession(txtUserName.Text, IsCookiePersistent);
            //Session User name is saved on the separate session variable
            Session["UserName"] = txtUserName.Text;
            //Access as set
            Access.SetModuleAccess();
            //Log the login time of the user
            User.DataCtrl.UserLog();
            //InsertDIDMonitoringParameters();    //robert modification 20121220

            if (this.ReturnURL == null) //this.ReturnURL = FormsAuthentication.GetRedirectUrl(txtUserName.Text, this.IsCookiePersistent);
            {
                //if the user has a remind password flag up
                //then the next page will pop up the reminder
                MessageHandling.Message = Access.CurrentUser.GetReminders();

                //all logins will redirect to the default page and the default page
                //the default page is a dummy page that will redirect then to their homepage
                //if session is null or expired they will be returned to the login page
                Response.Redirect("~/Default.aspx");
            }
        }
        else
        {
            //log in failed response
            switch (formAuth.LoginFailedCode)
            {
                case 0:
                    lblErrorLogin.Text = "Logon failed: Wrong username or password.";
                    break;
                case 1:
                    lblErrorLogin.Text = "Logon failed: User does not exist!";
                    break;
                case 2:
                    lblErrorLogin.Text = "Logon failed: User is deactivated!";
                    break;
                case 3:
                    lblErrorLogin.Text = "Logon failed: User is locked due to max password tries!";
                    break;
                default:
                    lblErrorLogin.Text = "Logon failed: Authentication Error!";
                    break;
            }
        }
        if (LoginClick != null) LoginClick(this, EventArgs.Empty);
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);
        Debug.WriteLine(ex.StackTrace);
        lblErrorLogin.Text = "Internal Error, Contact Gjenesis Admins." + ex.Message;
        //lblErrorLogin.Text = ex.Message;
        return;
    }


Source: .net

Leave a Reply