AsyncFileUpolad SerializationException

Last post 11-10-2009 2:00 PM by StrouMfios. 4 replies.

Sort Posts:

  • AsyncFileUpolad SerializationException

    11-10-2009, 12:00 PM
    • Member
      2 point Member
    • StrouMfios
    • Member since 08-06-2008, 5:19 AM
    • Posts 8

    I tried to upload files images using the asyncFileUpload control.

    I tried it on localhost and it worked perfectly.

    The problem I faced occured on production server.

    The fact is that I'm not using session !!

    Below are the error and the methods that I'm using.

     

    Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.

     

    [SerializationException: Type 'System.Web.HttpPostedFile' in Assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.]
    System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +7733643
    System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +258
    System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +111
    System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) +161
    System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) +51
    System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +410
    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +134
    System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1577


    Theese are the methods I'm using.

    protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) {
    string email = WriteYourEmailTXT.Text;
    var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).ToString("ddMMyyyy");
    string parentFolder = Server.MapPath("uploads");
    string childFolder = parentFolder + "\\" + email + "\\";
    if (!Directory.Exists(childFolder))
    Directory.CreateDirectory(childFolder);

    string counter = getCount();
    if (AsyncFileUpload1.HasFile) {
    string ext = getExtension(AsyncFileUpload1.FileName);
    string finalName = dt + "_" + counter + ext;
    string finalPath = childFolder + finalName;
    AsyncFileUpload1.SaveAs(finalPath);
    SetCount();
    SetFileName(finalName);
    }
    }

    protected void SetFileName(string fileName) {
    HttpCookie aCookie = Request.Cookies["FileName"];
    var filename = "";
    if (aCookie != null)
    if (aCookie.Value != "") {
    filename = aCookie.Value;
    }
    string newFileName = filename + "," + fileName;
    Response.Cookies["FileName"].Value = newFileName;
    }


    protected void SetCount() {
    HttpCookie aCookie = Request.Cookies["CountPhoto"];
    int cookieNum = 0;
    if (aCookie != null)
    if (aCookie.Value != "")
    cookieNum = int.Parse(aCookie.Value.ToString());

    string newvalue = (cookieNum + 1).ToString();
    Response.Cookies["CountPhoto"].Value = newvalue;
    }

     

    I'll apreciate any answer.
    Thanks in Advance

  • Re: AsyncFileUpolad SerializationException

    11-10-2009, 12:09 PM
    • All-Star
      59,262 point All-Star
    • anas
    • Member since 09-21-2006, 4:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,734
    • Moderator

    Hi,

    This is a known issue, the AsynchFileUpload control doesn't support the Out of Process (OOP) session mode.This means that you can use it only when the session mode is "InProc" (the default).

    This is because the Control use the session to store the uploaded file,

    Please see this thread for more details:

    http://forums.asp.net/p/1478889/3490074.aspx#3490074

    Regards,

    Anas Ghanem | Blog

  • Re: AsyncFileUpolad SerializationException

    11-10-2009, 1:05 PM
    • Member
      2 point Member
    • StrouMfios
    • Member since 08-06-2008, 5:19 AM
    • Posts 8

    I follow the link you sent me but unfortunatly I didn't understand how can i solve my problem.


    Might I change something in web.config file?



  • Re: AsyncFileUpolad SerializationException

    11-10-2009, 1:10 PM
    Answer
    • All-Star
      59,262 point All-Star
    • anas
    • Member since 09-21-2006, 4:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,734
    • Moderator

    You must make sure that the sessionState section in the web.cofig file is set to "InProc":

    <sessionState mode="InProc"></sessionState>

    If it's set correctly and you still get that error, then contact your hosting support and ask them to set your website as a virual directory in IIS.


    Regards,

    Anas Ghanem | Blog

  • Re: AsyncFileUpolad SerializationException

    11-10-2009, 2:00 PM
    • Member
      2 point Member
    • StrouMfios
    • Member since 08-06-2008, 5:19 AM
    • Posts 8

    Thank you very much anas.

Page 1 of 1 (5 items)