1

I have an ASP.NET page that has a FileUpload control inside. When I try to upload a third file I am getting:

System.OutOfMemoryException 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()

here's my code:

<td style="width: 60%; height: 67px; vertical-align: top">
    <div class="fileinputs" id="div2" style="left: 0px; top: 0px; width: 100%; vertical-align: middle">
        <div id="div3" class="fakefile" style="left: 0px; top: 0px; vertical-align: middle">
            <asp:TextBox ID="txtFileUpload" runat="server" Width="265px" CssClass="borde-form"
                Height="15px" ValidationGroup="docs" />
            <img name="imgExaminar" alt="Examinar" src="../../Images/botExaminar.gif" style="cursor: hand;
                width: 81px; height: 20px; vertical-align: middle" />
        </div>
        <asp:FileUpload EnableViewState="true" ID="fileUpload" runat="server" Width="368px"
            Height="19px" CssClass="hidden" />
    </div>
    <asp:CustomValidator ID="cvattachment" runat="server" OnServerValidate="cvattachment_ServerValidate"
        ControlToValidate="fileUpload" ErrorMessage="Existe un archivo con el mismo nombre"
        Font-Bold="False" Font-Names="Arial" Font-Size="X-Small" ValidationGroup="docs"></asp:CustomValidator>
</td>
<td style="width: 30%; height: 67px; vertical-align: top">
    <asp:ImageButton ID="imgAdjuntar" runat="server" ImageUrl="~/Images/botAdjuntar.GIF"
        OnClick="imgAdjuntar_Click" ValidationGroup="docs" Height="20px" Width="66px"></asp:ImageButton>
</td>

When I click on my imgAdjuntar, I am getting the error, but the imgAdjuntar_Click method is never called, but the Application_Error on the Global.asax is fired instead. Plus, none of my breakpoints are being stepped into, the error occurs before reaching the application code.

Maybe the control is the one that's failing? What can I do?

Thank you!

4
  • Does this help? System.OutOfMemoryException: Exception when uploading a file Commented Apr 29, 2014 at 17:49
  • I've already seen that, but the thing is that my code is never even reached! the error occurs even before anything is executed in my code. Commented Apr 29, 2014 at 18:09
  • I'm specifically thinking of the "maxRequestLength" web.config property mentioned in the question, and the link mentioned in the top-voted answer. Did you look at those two settings? Commented Apr 29, 2014 at 18:35
  • Yes, I changed those parameters but I am still getting the same error Commented May 8, 2014 at 19:12

1 Answer 1

3
+50

Make sure that you are not storing files within the ViewState.

In addition, try to disable the ViewState for the entire page.

Check the following treads, which may be helpful:

How do i handle 'System.OutOfMemoryException' in uploading?

Exception of type 'System.OutOfMemoryException' was thrown

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

1 Comment

That was it! I changed all ViewState storage, for Session storage. Thank you!

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.