C# 由于对象的当前状态,操作无效。当我选择下拉列表时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10697194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Operation is not valid due to the current state of the object. when i select dropdown list
提问by G.S Bhangal
i have radcombo boxes on aspx page and when i select any option from then it gives error`Server Error in '/' Application.
我在 aspx 页面上有 radcombo 框,当我从中选择任何选项时,它会在“/”应用程序中出现错误`服务器错误。
Operation is not valid due to the current state of the object. 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.
由于对象的当前状态,操作无效。说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
Exception Details: System.InvalidOperationException: Operation is not valid due to the current state of the object.
异常详细信息:System.InvalidOperationException:由于对象的当前状态,操作无效。
Source Error:
源错误:
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.
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常来源和位置的信息。
Stack Trace:
堆栈跟踪:
[InvalidOperationException: Operation is not valid due to the current state of the object.]
System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +2692302 System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +61
System.Web.HttpRequest.FillInFormCollection() +148[HttpException (0x80004005): The URL-encoded form data is not valid.] System.Web.HttpRequest.FillInFormCollection() +206
System.Web.HttpRequest.get_Form() +68
System.Web.HttpRequest.get_HasForm() +8735447
System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +97 System.Web.UI.Page.DeterminePostBackMode() +63 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +133
[InvalidOperationException:由于对象的当前状态,操作无效。]
System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +2692302 System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +61
System.Web。 HttpRequest.FillInFormCollection() +148[HttpException (0x80004005): URL 编码的表单数据无效。] System.Web.HttpRequest.FillInFormCollection() +206
System.Web.HttpRequest.get_Form() +68
System.Web.HttpRequest.get_HasForm() +8735447
System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +97 System.Web.UI.Page.DeterminePostBackMode() +63 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +133
Version Information: Microsoft .NET Framework Version:2.0.50727.3634; ASP.NET Version:2.0.50727.3634 `
版本信息:Microsoft .NET Framework 版本:2.0.50727.3634;ASP.NET 版本:2.0.50727.3634 `
采纳答案by Yuriy Galanter
Issue happens because Microsoft Security Update MS11-100 limits number of keys in Forms collection during HTTP POST request. To alleviate this problem you need to increase that number.
This can be done in your application Web.Config in the
<appSettings>section (create the section directly under<configuration>if it doesn't exist). Add 2 lines similar to the lines below to the section:<add key="aspnet:MaxHttpCollectionKeys" value="2000" /> <add key="aspnet:MaxJsonDeserializerMembers" value="2000" />The above example set the limit to 2000 keys. This will lift the limitation and the error should go away.
发生问题是因为 Microsoft 安全更新 MS11-100 在 HTTP POST 请求期间限制了表单集合中的键数。为了缓解这个问题,你需要增加这个数字。
这可以在您的应用程序 Web.Config
<appSettings>部分中完成(<configuration>如果它不存在,则直接创建该部分)。将 2 行类似于以下行的行添加到该部分:<add key="aspnet:MaxHttpCollectionKeys" value="2000" /> <add key="aspnet:MaxJsonDeserializerMembers" value="2000" />上面的示例将限制设置为 2000 个键。这将解除限制并且错误应该消失。
回答by Herman Schoenfeld
This can happen if you call
如果你打电话,这可能会发生
.SingleOrDefault()
on an IEnumerable with 2 or more elements.
在具有 2 个或更多元素的 IEnumerable 上。
回答by Elaine K
I know an answer has already been accepted for this problem but someone asked in the comments if there was a solution that could be done outside the web.config. I had a ListView producing the exact same error and setting EnableViewState to false resolved this problem for me.
我知道这个问题的答案已经被接受,但有人在评论中询问是否有可以在 web.config 之外完成的解决方案。我有一个 ListView 产生完全相同的错误并将 EnableViewState 设置为 false 为我解决了这个问题。

