7

I face this error from time to time,

ExecuteStep at line:0 at Column:0 The state information is invalid for this page and might be corrupted. (*)Invalid viewstate

Inner exception:

unhandled exception in Application_Error At Load at line:0 at Column:0 Invalid length for a Base-64 char array or string

debugging is enabled, and the pdb file exists, and as you see the debug info does not exactly tell me where it happened.

I'm using ASP.NET, C#, DotNet 4.5

this only occurs on a specific page's load.

[FormatException: Invalid length for a Base-64 char array or string.]
   System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength) +10545359
   System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) +130
   System.Convert.FromBase64String(String s) +41
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose) +66
   System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter2.Deserialize(String serializedState, Purpose purpose) +8
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose) +40
   System.Web.UI.HiddenFieldPageStatePersister.Load() +127

[ViewStateException: Invalid viewstate. 
    Client IP: ::1
    Port: 
    Referer: http://localhost:8000/ERP/MemberArea/Permits/Process_New.aspx
    Path: /ERP/MemberArea/Permits/Process_New.aspx
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
    ViewState: gIPYryxr+zwvGD5IdEv+hEYGPlEzkjxJDqtmnwmHt1TAjkdQ7AnFxm4v+85SO51MA3b+XRxf66nzwA8s8PqtrkQ8HdesiWnhkFp84+2ojOaAPw0+9FEw88EtB+2DH2Am7tv1qxS+WORKR0CducWqvJ65X7Q2iJH0yDwxCrNIOxIH/xgur3macyaqxYhZD99Jr+yrwiHY6q8v/IkdR41gz8UoGkU/J+5RB//I1RQZ8HAXLJhnEG4c5ZfJ0OD5kyyLI23S4JRaOR6vQT95nAdoxqSzsOLdiyYWPfrCyTk1gm8cPNLYzy1wC3JQ5I5446M/Y+2JjH1qde/0fhlKdsng4InIPOSFtWCckTe8aZBNFQvCd3fJdAByQvMVSXoRi9xNO3Ulwyd2nn/z0b5/ST/o+6TysKZ7Yeb/UPdnw5tXH9va0opHDZex289ZTaS7kpFWZaiXNbVbGNwBtRAtjqJXQb4+/C3pO6EWQh+snv929LyM52eDA+3F+6CZuFKSJo4naJL+lSL0A/sBMXC2tHEf3DPEAvbVSFb8nuYcpVJxddJkIw49GJ7BmwHk8gL9sON4ZaQdDmXe7HHGWFNdsfiZ2fB/HfTE/U/a6qmlOcciVAui+qTzxri1iGFhSa4QhkcgstPF5O6CLPYASsnCfmvBrIdQVB02j1yg2hqthtz5Z7gdKwqpr5qBmYI2q1W9OjTPf2LJjJExOmBm8/9DAY7hDt4VBJH9/WRQNz9TQh2ktn2tsZvyGBLvalyhHoGMpH...]

[HttpException (0x80004005): The state information is invalid for this page and might be corrupted.]
   System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +198
   System.Web.UI.HiddenFieldPageStatePersister.Load() +266
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +88
   System.Web.UI.Page.LoadAllState() +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6704
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +245
   System.Web.UI.Page.ProcessRequest() +72
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +58
   ASP.memberarea_permits_process_new_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\ERP\5da93c6f\27d5fbc5\App_Web_llo4zgw1.4.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
Amro
  • 1,369
  • 2
  • 10
  • 16
  • PS: the Applications seems to run even with those errors, but I'm afraid I'll miss something. – Amro Jan 05 '14 at 06:31
  • Does it happen on valid requests or your/someone's purely written automation of login/form filling is sometimes producing bad data? – Alexei Levenkov Jan 05 '14 at 06:35
  • Can you show code where its reproducible? – crthompson Jan 05 '14 at 06:35
  • @AlexeiLevenkov, It happens on a valid request. thank you – Amro Jan 05 '14 at 06:36
  • @paqogomez, unfortunely it's a whole system, I mean it does occur randomly, so I don't know where to look for it. – Amro Jan 05 '14 at 06:38
  • In Visual Studio you can break on all errors. Have you done this while debugging? – crthompson Jan 05 '14 at 06:40
  • 1
    If you can reproduce while debugger attached - make sure to turn off "Tools->Options->Debug->My Code only" and turn on "exception -> when thrown" to catch exceptions early. If you can't reproduce - setup WinDbg script to grab minidump on interesting exception, attach WinDbg and wait... – Alexei Levenkov Jan 05 '14 at 06:43
  • @paqogomez, yes I've already done that, and I can't catch it. – Amro Jan 05 '14 at 06:50
  • @AlexeiLevenkov, I'll take a look at WinDbg, if you have an example on how to do this it would be great. – Amro Jan 05 '14 at 06:51
  • Check http://blogs.msdn.com/b/pfedev/archive/2008/09/26/all-the-ways-to-capture-a-dump.aspx and http://blogs.msdn.com/b/tom/archive/2008/02/25/howto-capture-a-dump-on-a-specific-managed-exception.aspx – Alexei Levenkov Jan 05 '14 at 07:04
  • Ok it seems that the invalid length exception is an inner exception of the second invalid viewstate exception. I'll Include it in an Edit above. – Amro Jan 05 '14 at 07:16
  • 1
    You can read this answer - I bealive that can help you : http://stackoverflow.com/a/2551810/159270 – Aristos Jan 05 '14 at 10:01
  • @Aristos, thanks, I tried to override LoadPageStateFromPersistenceMedium, and it does catch the exception, but even then I don't know what really caused the exception. In my case it's not a problem of hacking because I'm testing it localy. – Amro Jan 05 '14 at 10:53
  • Update: @Aristos, the cause is that the page reloads 3 times, not sure why yet, but at least now I know why the Viewstate is corrupted, thanks to you! – Amro Jan 06 '14 at 08:05
  • 1
    @OHDev I have this happends, reload 2-3 times, maybe a fast double click, or some kind of javascript make it reloads.... – Aristos Jan 06 '14 at 08:31
  • @Aristos, it was my problem, I have a customized JQuery datepicker, and there was a javascript code to call an OnvalueChanged event, I was comparing two date values which were the same but had a different format, which caused the event to fire more than once somehow :) Please put your Link so I can choose it as an answer. Thanks again :) – Amro Jan 06 '14 at 08:55
  • @OHDev its ok, better describe your self your solution, make it answer, and accept it. – Aristos Jan 06 '14 at 09:10

1 Answers1

5

All credits go to @Aristos for providing his answer on another question: Click here

he provided three possibilities, my problem was that the page was reloading tripple times causing the viewstate to get corrupted.

I have a customized JQuery datepicker, and there was a javascript code to call an OnvalueChanged event, I was comparing two date values which were the same but had a different format, which caused the event to fire more than once somehow.

to debug this, put a breakpoint on the Page_Load event, and if it gets fired more than once, then start to remove some code/usercontrols, scripts until you catch the cause.

Community
  • 1
  • 1
Amro
  • 1,369
  • 2
  • 10
  • 16