Solved

Error on postback after adding ViewState

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now