Operation is not valid due to the current state of the object.

Topics: Developer Forum
May 14, 2012 at 9:58 AM

This might not be SHFB related, but it sounds related to the latest JSON serialization issue.

When my project has now been built completely, upon using search in the web-application, I encounter the following error:

Operation is not valid due to the current state of the object.

Stack trace:

[InvalidOperationException: Operation is not valid due to the current state of the object.]
   System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth) +580240
   System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) +155
   System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) +80
   System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) +44
   System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(String input) +74
   ASP.searchhelp_aspx.Render(HtmlTextWriter writer) +839
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060

Is this a known issue? Anything I can tweak?

This doesn't seem to address this issue:


May 14, 2012 at 7:36 PM

From what I can tell, that error is only thrown if the data being deserialized is not in the expected format.  Can you run it locally after building it using the "View Website (ASP.NET)" option in SHFB?  If it works there you might try uploading the files to the serve again in case there was a problem with them.  If not, can you e-mail me the index files?  They're located in the FTI\ sub-folder of the website output.  I can then try to see if there's something wrong with them.  My e-mail address is in the About box in the GUI and in the footer of the pages in the help file.



Jun 12, 2012 at 9:37 PM

I finally took the time to reply you, sorry about the delay.

Jul 3, 2012 at 9:40 PM

Hi Eric, did you receive my information, and was it useful?

Jul 4, 2012 at 8:37 PM

I recieved it but haven't had a chance to look into it yet.  I'll let you know when I do.



Jul 4, 2012 at 9:09 PM

No problem,
If you have instructions for me to do some of your dirtywork, just let me know.

Jul 10, 2012 at 12:59 PM
Edited Jul 10, 2012 at 12:59 PM

Hi Robert,

I had a similar issue as you described, here are the error details:

Exception Details: System.InvalidOperationException: Operation is not valid due to the current state of the object.
Source Error: 

Line 92:                 using(StreamReader sr = new StreamReader(ftiFile))Line 93:                 {Line 94:                     ftiWords = jss.Deserialize<Dictionary<string, List<long>>>(sr.ReadToEnd());Line 95:                 }Line 96:  
Source File: c:\inetpub\Help\SearchHelp.aspx    Line: 94 
Stack Trace: 

[InvalidOperationException: Operation is not valid due to the current state of the object.]   System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth) +929663   System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) +238   System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) +120   System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(String input) +94   ASP.searchhelp_aspx.Render(HtmlTextWriter writer) in c:\inetpub\Help\SearchHelp.aspx:94   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5290

I looked it up and this seems like a well-known issue by Microsoft


What I did was add the following key to the web.config file (please note that it is different than the one shown in stackoverflow)

<add key="aspnet:MaxJsonDeserializerMembers" value="1000" />

I incremented the value to 10000 and it seems to be working fine. Hope this helps you!

Jul 10, 2012 at 1:30 PM

Hi Jennifer,

I thought I already tried this, but I gues I did it incorrectly, your fix worked like charm!

Thanks a lot!

Jul 11, 2012 at 6:56 AM

Glad that it worked for you! :)

Also if I were you I would test the Search with different queries, and see if the error comes up again. In my case it did, and I incremented the value to resolve the issue.