1

I am uploading documents in my local drive after encrypting them and i have max uploading limit in web.config as

 <httpRuntime maxRequestLength="2147483647" executionTimeout="1000"/>

when document size is greator then 20mb following exception is shown

 Source Error: 
 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception 

 Stack Trace: 
 [OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.]
 System.IO.MemoryStream.set_Capacity(Int32 value) +93
 System.IO.MemoryStream.EnsureCapacity(Int32 value) +50
 System.IO.MemoryStream.WriteByte(Byte value) +130
 System.IO.BinaryWriter.Write(Byte value) +20
 System.Web.UI.SerializerBinaryWriter.WriteEncoded(Int32 value) +62
 System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value) +2081

 [ArgumentException: Error serializing value '644314' of type 'System.Int32.']
 System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value) +3371
 System.Web.UI.ObjectStateFormatter.Serialize(Stream outputStream, Object stateGraph) +141
 System.Web.UI.ObjectStateFormatter.Serialize(Object stateGraph) +57
 System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Serialize(Object state) +4
 System.Web.UI.Util.SerializeWithAssert(IStateFormatter formatter, Object stateGraph) +37
 System.Web.UI.HiddenFieldPageStatePersister.Save() +79
 System.Web.UI.Page.SavePageStateToPersistenceMedium(Object state) +108
 System.Web.UI.Page.SaveAllState() +315
 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2839

What would be the reason for this exception and how to solve this..

2
  • Looks like you trying to keep your file in ViewState and send back to client..? Commented Apr 4, 2013 at 10:49
  • I am saving document bytes in viewstate during upload. does this has any effect on memory. Commented Apr 4, 2013 at 10:52

1 Answer 1

3

You should not store the file in ViewState. It will have very bad impact on performance (since it will transmitted twice for each subsequent request.

You need to store the file in a temporary folder and then store the file path in ViewState instead. Just remember that you need some sort of cleanup routine that deletes files that are (for example) a day old.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.