An exception of type 'System.OutOfMemoryException

Last post 06-28-2009 1:51 PM by kaushalparik27. 4 replies.

Sort Posts:

  • An exception of type 'System.OutOfMemoryException

    06-24-2009, 5:29 PM
    • Member
      point Member
    • pointman
    • Member since 06-22-2009, 9:23 AM
    • Posts 12

    hi!

    I got the following error message:

    An exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll but was not handled in user code

    Here is the code:

    private void LoadImages()
                {
                      DataSet ds = new DataSet();
                      dt = ds.Tables.Add("images");
    
                      dt.Columns.Add("imagename");
                      dt.Columns.Add("size");
                      dt.Columns.Add("type");
                      dt.Columns.Add("Width");
                      dt.Columns.Add("Height");
                      dt.Columns.Add("deleteFile");
    
                      String path = Server.MapPath("../../News/Images/");
    
                      foreach (System.IO.FileInfo fil in new System.IO.DirectoryInfo(path).GetFiles("*.*"))
                      {
                            System.Drawing.Image objImg = System.Drawing.Image.FromFile(fil.FullName);
    
                            DataRow rowNew = dt.NewRow();
                            rowNew["Imagename"] = fil.Name;
                            rowNew["Size"] = fil.Length / 1024;
                            rowNew["type"] = fil.Extension;
                            rowNew["Width"] = objImg.Width;
                            rowNew["height"] = objImg.Height;
                            rowNew["deleteFile"] = fil.FullName;
                            dt.Rows.Add(rowNew);
                            objImg.Dispose();
    
                      }
    
                      Repeater1.Visible = true;
                      Repeater1.DataSource = dt;
                      Repeater1.DataBind();
    
                }

    And the error occurs at the System.Drawing.Image objImg = System.Drawing.Image.FromFile(fil.FullName);

    Any suggestions anyone?

    /Tyronne

  • Re: An exception of type 'System.OutOfMemoryException

    06-25-2009, 2:15 AM
    • Participant
      1,657 point Participant
    • paaresh
    • Member since 05-22-2007, 9:21 AM
    • Ahmedabad
    • Posts 255

    Hi,

    please check that your image file is damaged?

    if not then check its file attributes.

    Paresh

    [GTL-Ahmedabad]
    || Blog ||
  • Re: An exception of type 'System.OutOfMemoryException

    06-25-2009, 2:20 AM
    Answer

    pointman:
    foreach (System.IO.FileInfo fil in new System.IO.DirectoryInfo(path).GetFiles("*.*"))  

    as the above post suggested..

    [1] pls check that image may get corrupted- (you can try openning image in default image viewer and check whether its openning correctly)

    also there are other possibilities you can check :

    [1] image not in use

    [2] as you are getting the file with  - .GetFiles("*.*"))  - quite possible that there might be other files exists in the same folder other than image type (for example Thembs.db) and causing the problem

    [3] check that proper path of the file are getting in the code..

    hope it helps./.

    नमस्ते,
    [KaushaL] || BloG || MS MVP

    "I would love to change the world, but they won’t give me the source code"


    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: An exception of type 'System.OutOfMemoryException

    06-27-2009, 5:22 AM
    • Member
      point Member
    • pointman
    • Member since 06-22-2009, 9:23 AM
    • Posts 12

     Hi! Thx for the help!

    You were right about the Thembs file. When i delete the file it works greate!

    Thx!

    /Tyronne

  • Re: An exception of type 'System.OutOfMemoryException

    06-28-2009, 1:51 PM

    pleasure to help.. dont forget to resolve the thread and mark the answers. thanx./.

    नमस्ते,
    [KaushaL] || BloG || MS MVP

    "I would love to change the world, but they won’t give me the source code"


    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
Page 1 of 1 (5 items)