Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#输入字符串的格式不正确_C#_Formatexception - Fatal编程技术网

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

C#输入字符串的格式不正确,c#,formatexception,C#,Formatexception,运行下面的代码时,我有时会收到FormatException错误。异常似乎是随机抛出的。我的团队成员在运行代码时已看到错误,并将通知我。在几秒钟内,我将尝试使用相同的应用程序插入相同的数据,但不会得到异常。我在下面附上了一个格式异常文本的示例。异常意味着我正在尝试将十进制转换为int32,但在我分配的下面的值中,没有一个是十进制或int。有人遇到过这样的格式异常吗 foreach (var strPriceFile in lstPriceFiles) { var SoldToRecs =

运行下面的代码时,我有时会收到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:输入字符串的格式不正确。] System.Number.stringtonNumber(字符串str,numberstyle选项,NumberBuffer&Number,NumberFormatInfo信息,布尔parseDecimal)+12630933 System.Number.ParseInt32(字符串s、NumberStyles样式、NumberFormatInfo信息)+224 System.ComponentModel.Int32Converter.FromString(字符串值,NumberFormatInfo formatInfo)+46 System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext上下文,CultureInfo区域性,对象值)+497

[例外:90.90908893868948不是Int32的有效值。] System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext上下文,CultureInfo区域性,对象值)+8019613 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(对象o,类型类型,JavaScriptSerializer序列化程序,布尔throwOnError,对象和转换对象)+938181 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(对象o,类型类型,JavaScriptSerializer序列化程序,布尔throwOnError,对象和转换对象)+227 System.Web.Script.Serialization.ObjectConverter.AssignToPropertyOrField(对象propertyValue,对象o,字符串memberName,JavaScriptSerializer序列化程序,布尔throwOnError)+321 System.Web.Script.Serialization.ObjectConverter.ConvertDictionaryObject(IDictionary`2字典,类型类型,JavaScriptSerializer序列化程序,布尔throwOnError,对象和convertedObject)+1790 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(对象o,类型类型,JavaScriptSerializer序列化程序,布尔throwOnError,对象和转换对象)+115 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(对象o,类型类型,JavaScriptSerializer序列化程序,布尔throwOnError,对象和转换对象)+227 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(字符串输入)+126 Telerik.Web.UI.RadListBox.LoadPostData(字符串postDataKey,NameValueCollection postCollection)+184 System.Web.UI.Page.ProcessPostData(NameValueCollection postData,布尔fBeforeLoad)+1018 System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)+2653


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

此问题的解决方法可在此处找到:

您可以在这里看到解释:

以下是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>

Telerik.Web.UI.RadScheduler.prototype.saveClientState=函数(){
返回“{”scrollTop:“+Math.round(this.\u scrollTop)+”,
“scrollLeft”:“+Math.round(this._scrollLeft)+”,
“isDirty”:“+这个._isDirty+”}”;
} 
对于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>

Telerik.Web.UI.RadTreeView.prototype.saveClientState=函数(){
返回“{\”expandedNodes\”:“+this.\u expandedNodesJson+
“,\“collapsedNodes\”:“+this.\u collapsedNodesJson+
“,\“logEntries\”:“+this.\u logEntriesJson+
“,\“selectedNodes\”:“+this.\u selectedNodesJson+
“,\“checkedNodes\”:“+this.\u checkedNodesJson+
“,\“scrollPosition\”:“+Math.round(this.\u scrollPosition)+”}”;
} 
对于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>

Telerik.Web.UI.RadListBox.prototype.saveClientState=函数(){
返回“{”+
“\“isEnabled\”:“+此.\u已启用+
“,\“logEntries\”:“+this.\u logEntriesJson+
“,\“SelectedDices\”:“+这个。\你选择了Dices\”+
“,\“checkedDices\”:“+这个.\u checkedDices\”+
“,\“scrollPosition\”:“+Math.round(此.\u scrollPosition)+
"}";
} 


希望这能有所帮助。

您正在尝试反序列化为
int
属性。例外情况不会对您撒谎。字符串的格式错误。捕捉异常,显示字符串,您将看到格式有什么问题。该错误看起来像是您的代码在计算双浮点(而非十进制)数字90.1(近似值)。很可能生成JSON的内容并没有将double修改为int。虽然这个链接可以回答这个问题,但最好在这里包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能会无效。谢谢您的建议。更新。