Regarding Base-64: Trying to solve an ASP.NET issue…


Update: Thanks to WordPress.com automagically linking related posts to each other, I think I may have found a potential solution to this issue here: Invalid character in a Base-64 string (ASP.NET)

The problem seems to be with the ViewState. The ViewState is encrypted, and when an attempt is made to decrypt it on postback, the error is triggered.  The solution is actually quite simple: in the web.config file, set the ViewState not to be encrypted, like this:

<system.web>
<pages viewStateEncryptionMode=”Never”>
</pages>
</system.web>

You should really check out the rest of that article; it looks like it’s got a great explanation for what is actually occurring.

Also, this seems to be related to another message, “Invalid Viewstate.”

My original article is below the fold…

Hopefully, some of you fellow ASP.NET/C# programmers out there who’ve found this blog while looking for the Visual Studio 2008 post can give me a hand with these issues:

Invalid length for a Base-64 char array.

Error Message:
Invalid length for a Base-64 char array.
ExceptionType:
System.FormatException
Stack Trace:
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()

Invalid character in a Base-64 string.

Error Message:
Invalid character in a Base-64 string.
ExceptionType:
System.FormatException
Stack Trace:
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’ve been browsing forums and newsgroups most of the day trying to figure out what might be going on with both/either of these errors, but I’ve had no real luck so far. Any help from the community is very much appreciated in regard to this issue.

Thanks!

-Will

11 Comments

  1. Justin Wignall says:

    Will,

    Other than to say I get them occasionally too, I don’t have any help for you. No specific page or control causes it and it seems to occur quite randomly.

    One day I hope to find out why they happen but to be honest I’m not losing too much sleep over it (Until it stops me getting to zero bugs that is 🙂 )

    If you ever find out anything I’d be interested to hear.

    Justin

  2. willwm says:

    Justin,

    Are you using any Telerik controls in your web application? I found a tip in their forums that might help you out. (We’ve implemented the “fix” in our own application, but I haven’t been able to fully monitor the results yet.)

    http://www.telerik.com/community/forums/thread/b311D-cgcdh.aspx#99888

    The “fix” is to add the following line to web.config (within the system.web node):

    <pages enableViewStateMac=”false” />

    Let me know if this helps you out.

    Thanks for commenting!

    -Will

  3. willwm says:

    Here’s the code snip from the telerik page linked above:

    <?xml version="1.0"?>
    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <system.web>
    <pages enableViewStateMac="false" />
    </system.web>
    </configuration>

  4. Justin Wignall says:

    I do indeed use Telerik controls (for now). In the environment the error is coming in on, setting enableViewStateMac to false is acceptable so that will be the way I go.

    Less than ideal from Telerik I guess but I can live with it.

    Thanks for following up, appreciate it.

    Justin

  5. willwm says:

    Justin,

    Just out of curiosity, are you using the Prometheus version of the RadControls, or the previous version?

    -Will

  6. Justin Wignall says:

    Previous version (Q1 2007), my subscription license has now expired.

    I am mid way through migrating old code to

    Native .NET TreeView
    FCKEditor – http://www.fckeditor.net/
    ZedGraph – http://zedgraph.org/

    as open source alternatives with a great deal of success. TreeView isn’t so great, my eyes are on extJS .NET projects such as Coolite for this one but we get by.

  7. TV says:

    i am using webcombo dropdown thirdparty control. i also get the invalid base 64 error.

    1. Tyler Tomsen says:

      The solution on the telerik site appears to be a band aid. The real problem is that the machinekey in the web.config must be set to the same value on every server in the web farm.

      http://msdn.microsoft.com/en-us/library/ff649308.aspx

      The solution on the telerik forum will solve the issue, because it turns off encryption, but if you set the encryption key manually on all servers, in the web.config, you’ll get the fix and still retain encryption.

      1. willwm says:

        Excellent info; thank you for sharing! =)

      2. mfscdev says:

        We get the error in an application that only utilizes a single web server, and the app does use Telerik controls too.

Leave a Reply to willwm Cancel reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Facebook photo

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

Connecting to %s