Take the 2-minute tour ×

I have webservice, with method:

public byte[] GetFile(string FName)
    System.IO.FileStream fs1 = null;
                fs1 = System.IO.File.Open(FName, FileMode.Open, FileAccess.Read);
    byte[] b1 = new byte[fs1.Length];
    fs1.Read(b1, 0, (int)fs1.Length);
    return b1; 

and it works with small file like 1mb, but when it comes to photoshop's file (about 1,5gb) I get:


on this line:

Byte[] img = new Byte[fs.Length];

The idea is I have winforms application which get this file and saving it on local disc.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

This all depends on where the exception is being thrown. Most likely what is happening is that a file that size is going into the Large Object Heap (LOH) and the memory fragmentation is causing that problem.




Link to a similiar SO question:

share|improve this answer

Your Answer


