title: Unable to evaluate expression because the code is optimized or native frame is on top of call stack
body: <p>Unable to evaluate expression because the code is optimized or native frame is on top of call stack. Please help me regarding this topic. The error is displaying in RedirectAndPOST(this.Page, "strDTIurl", ldata). </p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      if (!IsPostBack)
      {
          CommonProperties gCommonProperties = new CommonProperties();
          HttpContext _context = HttpContext.Current;
          gCommonProperties = (CommonProperties)_context.Items["Pay"];
          //ThreadStart childthreat = new ThreadStart();
          NameValueCollection ldata = new NameValueCollection();
          ThreadStart childthreat = new ThreadStart(childthreadcall);
          Thread child = new Thread(childthreat);
          child.Start();
          ldata.Add("transactionDetail", gCommonProperties.transactionDetail);
          ldata.Add("depositedBy", gCommonProperties.depositedBy);
          ldata.Add("contactNo", gCommonProperties.contactNo);
          ldata.Add("emailId", gCommonProperties.emailId);
          ldata.Add("district", gCommonProperties.district);
          ldata.Add("depositorAddress", gCommonProperties.depositorAddress);
          ldata.Add("deptName", gCommonProperties.deptName);
          ldata.Add("otherParameters", "(ReqID=" + gCommonProperties.ReqID.ToString() + "!~!CircleID=" + gCommonProperties.CircleName + "!~!UserCode=" + gCommonProperties.UserCode + "!~!redirect_url="+strRTNurl+")");
          Session["redirect"] = gCommonProperties.paymentConfirmPageURL;
          if (gCommonProperties.optionalParm != string.Empty)
          {
              Session["ReferId"] = gCommonProperties.optionalParm;
          }
          RedirectAndPOST(this.Page, "strDTIurl", ldata);
      }
  }
   public static void RedirectAndPOST(Page page, string destinationUrl, NameValueCollection data)
  {
  
      //Prepare the Posting form
      string strForm = PreparePOSTForm(destinationUrl, data);
      //Add a literal control the specified page holding 
      //the Post Form, this is to submit the Posting form with the request.
      page.Controls.Add(new LiteralControl(strForm));
  }
  private static String PreparePOSTForm(string url, NameValueCollection data)
  {
      //Set a name for the form
      string formID = "PostForm";
      //Build the form using the specified data to be posted.
      StringBuilder strForm = new StringBuilder();
      strForm.Append("&lt;form id=\"" + formID + "\" name=\"" +
                     formID + "\" action=\"" + url +
                     "\" method=\"POST\" &gt;");//target=\"TheWindow\"
  
      foreach (string key in data)
      {
          strForm.Append("&lt;input type=\"hidden\" name=\"" + key +
                         "\" value=\"" + data[key] + "\"&gt;");
      }
  
      strForm.Append("&lt;/form&gt;");
      //Build the JavaScript which will do the Posting operation.
      StringBuilder strScript = new StringBuilder();
      strScript.Append("&lt;script language='javascript'&gt;");
      //strScript.Append("javascript:void window.open('','TheWindow','menubar= 1,scrollbars=1,width=600,height=400');");
      strScript.Append("var v" + formID + " = document." +
                       formID + ";");
      strScript.Append("v" + formID + ".submit();");
      strScript.Append("&lt;/script&gt;");
      //Return the form and the script concatenated.
      //(The order is important, Form then JavaScript)
      return strForm.ToString() + strScript.ToString();
  }
  </code></pre>