title: C# Input string was not in a correct format. Conversion issue on server not in local machine
body: <p>I am croppping the image and save. On btnsave_click I am converting the hiddenfield value to decimal. There is no error on local machine but when published to server it gives below error.</p>
  
  <p><strong>Detailed exception on server</strong>:</p>
  
  <h2><em>Input string was not in a correct format.</em></h2>
  
  <p>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.</p>
  
  <p>Exception Details: System.FormatException: Input string was not in a correct format.</p>
  
  <p>Source Error:</p>
  
  <p>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</p>
  
  <p>Stack Trace:</p>
  
  <blockquote>
    <p>[FormatException: Input string was not in a correct format.]<br>
    System.Number.StringToNumber(String str, NumberStyles options,
    NumberBuffer&amp; number, NumberFormatInfo info, Boolean parseDecimal)
    +10726387    System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt) +172<br>
    System.Convert.ToDecimal(String value) +68<br>
    IngredientMatcher.Pages.ImageCropPopup.btnsave_Click(Object sender,
    EventArgs e) +104<br>
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9552602<br>
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    eventArgument) +103<br>
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    eventArgument) +10<br>
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument) +13<br>
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    +35    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    +1724</p>
  </blockquote>
  
  <p><strong>Code :</strong>:</p>
  
  <pre><code>protected void btnsave_Click(object sender, EventArgs e)
  {
      string ImageName = ViewState["ImageName"].ToString();
      int www = Convert.ToInt32(Math.Round(Convert.ToDecimal(W.Value)));
      int hhh = Convert.ToInt32(Math.Round(Convert.ToDecimal(H.Value)));
      int xxx = Convert.ToInt32(Math.Round(Convert.ToDecimal(X.Value)));
      int yyy = Convert.ToInt32(Math.Round(Convert.ToDecimal(Y.Value)));
      int w = (www == 0) ? 0 : www;
      int h = (hhh == 0) ? 0 : hhh;
      int x = (xxx == 0) ? 0 : xxx;
      int y = (yyy == 0) ? 0 : yyy;
  
      byte[] CropImage = Crop(Server.MapPath(" ") + "\\" + upPath + ImageName, w, h, x, y);
      using (MemoryStream ms = new MemoryStream(CropImage, 0, CropImage.Length))
      {
          ms.Write(CropImage, 0, CropImage.Length);
          using (SD.Image CroppedImage = SD.Image.FromStream(ms, true))
          {
              string SaveTo = Server.MapPath("") + "\\" + CropPath + "crop" + ImageName;
  
              CroppedImage.Save(SaveTo, CroppedImage.RawFormat);
              imgCropped.BorderWidth = 1;
              imgCropped.ImageUrl = CropPath + "crop" + ImageName;
          }
      }
      string CroppedImg = "crop" + ViewState["ImageName"].ToString();
  
      ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "OpenPopUp", "javascript:SaveAndClose('" + CroppedImg + "');", true);
  }
  </code></pre>
  
  <p>Thanks in advance.</p>