Reputation: 21
I am receiving a FormatException error sometimes when running the below code. The exception seems to be thrown at random. Members of my team have seen the error while running the code and will inform me. Within seconds I will try to insert the same data using the same app and not get it the exception. I have attached an example of the format exception text below. The exception implies that I am trying to convert a decimal to an int32, but in the values below that I am assigning, none are decimal or int. Has anyone come across a format exception like this?
foreach (var strPriceFile in lstPriceFiles)
{
var SoldToRecs = DbContext.RFQ_SoldTo_PriceLists.Where(us => us.UserId == ERepGuid && us.RFQ_SoldTo_CustNbr == strSoldTo[0] && us.RFQ_SoldTo_CustSeq == strSoldTo[1] && us.IngresFileName == strPriceFile);
if (SoldToRecs.Count() == 0)
{
var PriceFile = new RFQ_SoldTo_PriceList();
PriceFile.UserId = ERepGuid;
PriceFile.RFQ_SoldTo_CustNbr = strSoldTo[0];
PriceFile.RFQ_SoldTo_CustSeq = strSoldTo[1];
PriceFile.IngresFileName = strPriceFile;
PriceFile.CreatedBy_UserName = strCreatorName;
PriceFile.CreatedBy_DateTime = DateTime.Now;
PriceFile.Active_YN = true;
DbContext.RFQ_SoldTo_PriceLists.InsertOnSubmit(PriceFile);
}
}
FormatException: Input string was not in a correct format.] System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +12630933 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +224 System.ComponentModel.Int32Converter.FromString(String value, NumberFormatInfo formatInfo) +46 System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) +497
[Exception: 90.90908893868948 is not a valid value for Int32.] System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) +8019613 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) +938181 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) +227 System.Web.Script.Serialization.ObjectConverter.AssignToPropertyOrField(Object propertyValue, Object o, String memberName, JavaScriptSerializer serializer, Boolean throwOnError) +321 System.Web.Script.Serialization.ObjectConverter.ConvertDictionaryToObject(IDictionary`2 dictionary, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) +1790 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) +115 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) +227 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(String input) +126 Telerik.Web.UI.RadListBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +184 System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +1018 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2653
Upvotes: 2
Views: 3667
Reputation: 96
Your issue may caused by Google Chrome zoom-in/out issue, as long as your are using RadScheduler, RadListBox, and RadTreeView, as stated by Hristo Valyavicharski in the links below. In this case, you can reproduce this issue by zooming-in or out on Google Chrome and perform postback again.
The work-around for this issue can be found here:
http://www.telerik.com/forums/system-formatexception-78e82e51af27#KkKRUtkEq0ST4A09XY_eZQ
You can see the explanation here:
http://www.telerik.com/forums/system-formatexception-78e82e51af27#Ww7bQEwfgUiShf9gFFmxBg
Below are the fixes provided by Hristo Valyavicharski:
For RadScheduler:
<script type="text/javascript">
Telerik.Web.UI.RadScheduler.prototype.saveClientState = function () {
return '{"scrollTop":' + Math.round(this._scrollTop) + ',
"scrollLeft":' + Math.round(this._scrollLeft) + ',
"isDirty":' + this._isDirty + '}';
} </script>
For RadTreeView:
<script type="text/javascript">
Telerik.Web.UI.RadTreeView.prototype.saveClientState = function () {
return "{\"expandedNodes\":" + this._expandedNodesJson +
",\"collapsedNodes\":" + this._collapsedNodesJson +
",\"logEntries\":" + this._logEntriesJson +
",\"selectedNodes\":" + this._selectedNodesJson +
",\"checkedNodes\":" + this._checkedNodesJson +
",\"scrollPosition\":" + Math.round(this._scrollPosition) + "}";
} </script>
For RadListBox:
<script type="text/javascript">
Telerik.Web.UI.RadListBox.prototype.saveClientState = function() {
return "{" +
"\"isEnabled\":" + this._enabled +
",\"logEntries\":" + this._logEntriesJson +
",\"selectedIndices\":" + this._selectedIndicesJson +
",\"checkedIndices\":" + this._checkedIndicesJson +
",\"scrollPosition\":" + Math.round(this._scrollPosition) +
"}";
} </script>
Hope this helps.
Upvotes: 4