Solved

Error on postback after adding ViewState

Posted on 2008-10-16
5
4,333 Views
Last Modified: 2013-12-17
After adding the line ViewState["CachedControls"] = data to my property, I now receive this error on a postback:

"A Runtime Error has occurred.
Do you wish to Debug?
Line: 4723
Error: Sys.WebForms.PageRequestManagerServerErrorException: Error serializing value 'System.Collections.Generic.List`1[System.Collections.IEnumerable]' of type 'System.Collections.Generic.List`1[[System.Collections.IEnumerable, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].'"

I have Script Manager and UpdatePanel controls on the page, and it breaks into generated JavaScript code within an onReadyStateChange event.  The call stack is extremely unhelpful in this matter.
private List<IEnumerable> ControlData
{
	get 
	{
		List<IEnumerable> data =(List<IEnumerable>)ViewState["CachedControls"];
		if (data == null)
		{
			EditController editControl = new EditController(SearchType); 
			data = editControl.GetData();
			ViewState["CachedControls"] = data;
		}
 
		return data; 
	}
}

Open in new window

0
Comment
Question by:PerlChaser
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:JunkMan
ID: 22736016
what exactly is .getData() returning, one of the IEnumerable's returned is not marked a Serializable

like so:
[Serializable]
public class foo:IEnumerable{
 
}

Open in new window

0
 
LVL 1

Author Comment

by:PerlChaser
ID: 22736136
I will get back to you on this tomorrow, I need to head home.

PerlChaser
0
 
LVL 1

Author Comment

by:PerlChaser
ID: 22739964
GetData returns an IEnumerable list containing:
1. Dictionary<string, string>
2. IEnumerable<Term>
Term is marked Serializable.
0
 
LVL 3

Accepted Solution

by:
JunkMan earned 125 total points
ID: 22741563
I vaguely remember having issues when serializing dictonaries. Could you trim the getData method to return either one or the other type? that way you will know exactly which one is causing you the problem.

Also double check if Term is not referring to any object that might not be serializable.
0
 
LVL 1

Author Comment

by:PerlChaser
ID: 22742657
Yes, serializing this object was the problem.  I chose to store just the Dictionary in the ViewState since that was the only piece I needed between calls.  Thank you very much for your help, JunkMan.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question