Maximum memory for string ? . System.MemoryOutOfException Occurs when reading the Content of the file and Storing it in a string. RRS feed

  • Question

  • User-1155932461 posted


    I have a C++ code which reads a file [vtk file - its similar to text file only]. and try to store it in string.

    here's the code:

    String^ ParallelProjectionRenderer::GetVolumeDataAsString(String^ FileName)

        vtkSmartPointer<vtkDataSetWriter> sWriter = vtkSmartPointer<vtkDataSetWriter>::New();

        String^ FileName = "D:\\Users\\...";

        char * sptName = static_cast<char *>(Marshal::StringToHGlobalAnsi(FileName).ToPointer());







        String^ result= File::ReadAllText(FileName);   [it breaks here with system.memoryoutofexception when the file size is huge]

        return result;


    this code executes fine when the file size is less than 8mb.

    I wanted to know whats the maximum memory allocated to the string.

    As a workaround i skipped reading out in C++ code. and i tried to read the file contents in asp.net C# code and store it on string.

    Same sort of exception came.

    Basically i need this result in string bcoz, I need to communicate with the Silverlight component.

    As far as i know, the WebForm to silverlight communication is done via javascript using string message.

    So is there a way for this issue?

    Thanx in advance,


    Tuesday, October 20, 2009 6:28 AM

All replies

  • User1130775117 posted

    My hunch is that your limit is from an IIS setting for maximum size, think it's in machine.config on the webserver.

    Tuesday, April 6, 2010 5:46 PM