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

About Ramesh Sringeri

Yet another chaos monkey. View all posts by Ramesh Sringeri

3 responses to “ASP.Net AJAX JavaScript Serialization Error

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 489 other followers

%d bloggers like this: