Solved

Error on postback after adding ViewState

Posted on 2008-10-16
5
4,274 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASCX file or a newer alternative? 1 34
Creating a route in asp.net webforms 2 25
Deploying to Azure 3 27
Calculate number of nights between two dates 5 19
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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