none
OutOfMememoryException when use XmlReader.ReadElementContentAsBase64() on large file (>100MB) RRS feed

  • Question

  • Hi, we get an OutOfMemoryException when to read an XmlReader  (XmlTextReader) calling the method ReadElementContentAsBase64.
    Note that XmlReader input come from a Word file larger than 100MB. Below is the piece of code. Any idea how to solve this?
    We get the error only on office 32bit, for office 64bit everything is ok.
        public override object ParseContent(XmlReader input)
            {
                FileInfo info = GetNextFileInfo();
                if (input.IsEmptyElement)
                {
                    input.Read();
                    File.Create(info.FullName).Close();
                }
                else
                {
                    FileStream output = File.Create(info.FullName, 512);
                    byte[] buffer = new byte[512];
                    int readBytes;
                    while ((readBytes = input.ReadElementContentAsBase64(buffer, 0, 512)) > 0)
                    {
                            output.Write(buffer, 0, readBytes);
                    }
                    output.Flush();
                    output.Close();
                }
             ///
            }

    • Edited by M4TT3 Tuesday, January 10, 2017 5:09 PM
    Tuesday, January 10, 2017 2:20 PM

All replies

  • Hi M4TT3,

    Do you want to read a word file and create a file based on this XmlReader? Based on your description, it seems it is related with large file.

    I would suggest you share us more information about your requirement, and then we could try to check whether there is any workaround.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 11, 2017 8:38 AM
  • Hi, Edward. 

    So, i have a word add-in that communicate with a java server. The document is stored in a database, and when we would like to open that document with Word, the data is retrieved by the server,  we create the XmlTextReader in the deserialization process, then we would like to read it, for the creation of the file on the disk and effectively open it. Yes the problem is with the large file, on 32bit MS-WORD the command ReadElementContentAsBase64 result in an OutOfMemoryException only for file that are larger than 100MB. So i would like to know if there is another manner to read the XmlTextReader. 

    Thanks

    Best regards. 

    M. 

    Wednesday, January 11, 2017 9:53 AM
  • Hi M4TT3,

    Do you mean you develop with Word VSTO add in? Do you store word file by binary or xml in SQL Server? How did you open and retrieve data? Did you open generated file in Word add-in or server side?

    Based on your description, I am afraid the current solution is changing Office 32 bit to office 64 bit. As you know, Office 64 bit is better than Office 32 bit at handing large Office file. From code, XmlReader already provides fast way to process file.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 12, 2017 6:33 AM