ASP.Net AJAX JavaScript Serialization Error

Ran into an “Out of Stack Space” error trying to serialize an ASP.Net AJAX Array object. Not sure why, yet.

Here is the scenario with simplified code.

1. Default.aspx

<form id=”form1″ runat=”server”>
<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>
<Scripts>
<asp:ScriptReference Path=”~/Scripts/MainScript.js” NotifyScriptLoaded=”true” />
</Scripts>
</asp:ScriptManager>
<div>Main Content Page</div>
<div>
<iframe id=”mainContent” src=”Content.aspx” runat=”server”></iframe>
</div>
</form>

2. MainScript.js

function getObject(){
return new Array();
}

function function1(obj){
var s=Sys.Serialization.JavaScriptSerializer.serialize(obj);
alert(s);
}

function function2(){
var obj=getObject();
var s=Sys.Serialization.JavaScriptSerializer.serialize(obj);
alert(s);
}

3. Content.aspx

<form id=”form1″ runat=”server”>
<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>
<Scripts>
<asp:ScriptReference Path=”~/Scripts/ContentScript.js” NotifyScriptLoaded=”true” />
</Scripts>
</asp:ScriptManager>
<div>
Content Page
<button id=”btnShowWin” onclick=”serializeObject()”>Serialize Object</button>
</div>
</form>

4. ContentScript.js

function serializeObject(){
var obj=window.top.getObject();
window.top.function1(obj); // <– This works fine

obj=new Array();
window.top.function1(obj); // <– this causes an Out of Stack Space error

}

So basically, I have a web page (default.aspx) with an IFrame on it that hosts a content page (content.aspx). Clicking the
“Serialize Object” button calls the JavaScript function serializeObject(). The serialization works fine for Array objects created in the top window (outside the frame). However if the array object is created in the IFrame, serialization bombs with an out of stack space error. I stepped through ASP.Net AJAX JS files and what I discovered is, the process goes into an endless loop trying to figure out the type of the array object. Endless call to Number.IsInstanceOf and pretty soon you get an out of stack error. I am unable to put a finger on the issue.

Any ideas as to why this could be happening?

kick it on DotNetKicks.com

~ by Ramesh Sringeri on February 14, 2008.

One Response to “ASP.Net AJAX JavaScript Serialization Error”

  1. [...] AJAX JavaScript Serialization Error This entry was written by Ramesh Sringeri. Bookmark the permalink. Follow any comments here with the RSS feed for this post.Content related [...]

Leave a Reply