views:

10671

answers:

6

I have very little to go on here. I cant reproduce this locally, but when users get the error I get an auto email exception notification.

Message: Invalid length for a Base-64 char array.

Call Stack: at System.Convert.FromBase64String(String s) at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) at System.Web.UI.HiddenFieldPageStatePersister.Load()

I'm inclined to think there is a problem with data that is being assigned to viewstate. For example:

List<int> SelectedActionIDList = GetSelectedActionIDList();
ViewState["_SelectedActionIDList"] = SelectedActionIDList;

Not being able to reproduce the error locally makes it difficult to guess what the source of the error is.

If anyone has had any experience with this error I would really like to know what you found out.

+3  A: 

I've seen this error caused by the combination of good sized viewstate and over aggressive content-filtering devices/firewalls (especially when dealing with K-12 Educational institutions).

We worked around it by storing Viewstate in SQL Server. Before going that route, I would recommend trying to limit your use of viewstate by not storing anything large in it and turning it off for all controls which do not need it.

References for storing ViewState in SQL Server:
MSDN - Overview of PageStatePersister
ASP Alliance - Simple method to store viewstate in SQL Server
Code Project - ViewState Provider Model

Jimmie R. Houts
I copied the veiwstate of the page and pasted it into Word. It was over 86000 characters long. That seems like too much.
Slim
Yikes, I'm running into the problem now. I have turned ViewState off for all controls that I possibly can. I am using a Wizard control with several pages and lots of content. Any advice?
Mike C.
@Mike C., this is a very frustating problem! You could break the content of each page of the wizard into user controls and load the content on demand (via ajax?). Of course, this is only a solution for that one page, if you begin to experience the problem on a consistent basis, you may want to consider storing viewstate in your database. I have updated my answer with references for storing viewstate in SQL Server.
Jimmie R. Houts
+3  A: 

My guess is that something is either encoding or decoding too often - or that you've got text with multiple lines in.

Base64 strings have to be a multiple of 4 characters in length - every 4 characters represents 3 bytes of input data. Somehow, the view state data being passed back by ASP.NET is corrupted - the length isn't a multiple of 4.

Do you log the user agent when this occurs? I wonder whether it's a badly-behaved browser somewhere... another possibility is that there's a proxy doing naughty things. Likewise try to log the content length of the request, so you can see whether it only happens for large requests.

Jon Skeet
+1  A: 

Take a look at your httphandlers. I've been noticing some weird and completely random errors over the past few months after I implemented a compression tool (Telerik). I was noticing errors like:

System.Web.HttpException: Unable to validate data.

System.Web.HttpException: The client disconnected.---> System.Web.UI.ViewStateException: Invalid viewstate.

and

System.FormatException: Invalid length for a Base-64 char array.

System.Web.HttpException: The client disconnected. ---> System.Web.UI.ViewStateException: Invalid viewstate.

I blogged about this here: http://dot-net-sam.blogspot.com/2009/08/random-errors-invalid-length-for-base.html

+1  A: 

After urlDecode processes the text, it replaces all '+' chars with ' ' ... thus the error. You should simply call this statement to make it base 64 compatible again:

        sEncryptedString = sEncryptedString.Replace(' ', '+');
jalchr
God bless you, you saved my sanity :-)
5arx
A: 

This is because of a huge view state, In my case I got lucky since I was not using the viewstate. I just added enableviewstate="false" on the form tag and view state went from 35k to 100 chars

Shash
A: 

This isn't an answer, sadly, but after running into the intermittently for some time, and finally being annoyed enough to try to fix it, I have yet to find a fix, BUT I have a determined recipe for reproducing my problem, which might help others.

In my case it is SOLELY a localhost problem, on my dev. machine that also has the app's DB. It's a .NET 2.0 app I'm editing w/VS2005, the win7 64 bit machine also has VS2008 and .NET 3.5 installed.

Here's what will generate the error, from a variety of forms:

  1. Load a fresh copy of the form.
  2. Enter some data, and/or postback with any of the form's controls. As long as there are no significant delay, repeat all you like, and no errors occur.
  3. Wait a little while (1 or 2 minutes maybe, not more than 5), and try another postback.

A minute or two delay "waiting for localhost" and then "Connection was reset" by the browser, and global.asax's application error trap logs:

    Application_Error event: Invalid length for a Base-64 char array.
Stack Trace: at System.Convert.FromBase64String(String s) at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) at System.Web.UI.HiddenFieldPageStatePersister.Load()

In this case, it is not the SIZE of the viewstate, but something to do with page and/or viewstate caching that seems to be biting me. Setting parameters enableEventValidation false, and viewStateEncryption Never in the Web.config did not change the behavior. Neither did setting the maxPageStateFieldLength to something modest.

fortboise