gpt4 book ai didi

C# 输入字符串的格式不正确

转载 作者:行者123 更新时间:2023-11-30 21:57:46 26 4
gpt4 key购买 nike

我在运行以下代码时有时会收到 FormatException 错误。异常似乎是随机抛出的。我的团队成员在运行代码时看到了错误,并会通知我。在几秒钟内,我将尝试使用相同的应用程序插入相同的数据,而不是让它出现异常。我在下面附上了格式异常文本的示例。异常意味着我正在尝试将小数转换为 int32,但在我分配的以下值中,没有一个是小数或 int。有没有人遇到过这样的格式异常?

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

最佳答案

只要您使用 RadScheduler、RadListBox 和 RadTreeView,您的问题可能是由 Google Chrome 放大/缩小问题引起的,如 Hristo Valyavicharski 在下面的链接。在这种情况下,您可以通过放大或缩小 Google Chrome 并再次执行回发来重现此问题。

可在此处找到解决此问题的方法:
http://www.telerik.com/forums/system-formatexception-78e82e51af27#KkKRUtkEq0ST4A09XY_eZQ

你可以在这里看到解释:
http://www.telerik.com/forums/system-formatexception-78e82e51af27#Ww7bQEwfgUiShf9gFFmxBg

以下是 Hristo Valyavicharski 提供的修复:

对于 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>

对于 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>

对于 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>


希望这对您有所帮助。

关于C# 输入字符串的格式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30515831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com