none
Range.Document.WordOpenXML giving InSufficient Memory exception RRS feed

  • Question

  • I am try to parse the word document in following code:

    XDocument.Parse(range.Document.WordOpenXML), I found that range.Document.WordOpenXml is throwing "Insufficient Memory" exception for word document. Can somebody helps me, why it is happening?  PFA.

    Thanks,

    Sakshi

    Friday, March 23, 2018 5:55 AM

Answers

  • Hi Sakshi,

    To update Word 2016 to the latest version, we can update it via File->Account->Update Options->Update Now.

    And the available updates are based on the update channel and if you were not use the Monthly Channel we can switch it manually to get the latest update by following the article below:

    How to switch from Semi-Annual Channel to Monthly Channel for the Office 365 suite

    Please feel free to let me know if you still have the problem.

    Regards & Fei


    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.

    • Marked as answer by S Goyal Friday, April 6, 2018 5:01 AM
    Friday, April 6, 2018 1:02 AM
    Moderator

All replies

  • Hi Sakshi,

     

    Please add the following code, and check which line will get you the exception ,line 1 or line2?

     

    public string result;                                          

    result= range.Document.WordOpenXML;     //line1

    XDocument.Parse(range.Document.WordOpenXML)   //line2


    Best Regards,
    Leon Lu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, March 26, 2018 2:05 AM
  • Hi Leon,

    result= range.Document.WordOpenXML(line 1)  is giving the exception.

    Thanks,

    Sakshi

    Monday, March 26, 2018 5:31 AM
  • Hi ,

     

    Our forum focus on a software called Microsoft Teams, based on your description, the problem is related to the word for developers, so I moved this thread to the word for developers forum.

    Thanks for your understanding.


    Best Regards,
    Leon Lu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, March 26, 2018 7:52 AM
  • Hello S Goyal,

    What's  the "range"? It should be a range of a word document. Does this issue occurs on specific document or every document?

    Could you share a simply whole code so we could reproduce your issue? If it is only related to specific document.

    We would suggest you share a simply document for testing. 

    For sharing file, you could share the file via Cloud Storage, such as One Drive, and then put link address here. Thanks for understanding.

    Best Regards,

    Terry


    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.

    Monday, March 26, 2018 10:04 AM
  • Hi Terry,

    It is happening with a specific document. Please refer below is the link for the document.

    https://drive.google.com/file/d/1rBH9hCcoj48qAwbfvCnp3j_A5vV_ms6C/view?usp=sharing

    This document contains images.Below is code we are using:

    Application app = new Application();
    Console.WriteLine("Please give the document path: ");
    string path = Console.ReadLine();
    Document doc = app.Documents.Open(path);
    (Microsoft.Office.Interop.Word.Range)range = doc.Content;
    
    var s = range.Document.WordOpenXML;
    var xdoc = XDocument.Parse(s);

    Tuesday, March 27, 2018 5:16 AM
  • Hello S Goyal,

    I failed to reproduce your issue using the file you shared.

    During testing, I found that range.Document.WordOpenXML returnd a string with 111182458 length and according to the error message, I think the reason is that your PC does not have enough memory to handle the string.

    Please try to refer to below link to handle large string in C#

    C# Very Large String Manipulation (Out of Memory Exception)

    Besides, expend your pc memory or test on a pc with large memory may be also an efficient solution for it.

    Best Regards,

    Terry


    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.


    Tuesday, March 27, 2018 8:19 AM
  • Hi Terry,

    Please find the below screenshot my system details. I am having 16 GB of RAM.

    

    Tuesday, March 27, 2018 9:56 AM
  • Hello S Goyal,

    What's the project you are developing? Have you tried to compile targeting X64 and .net framwork 4.5 and latter as the Loudenvier said in the link?

    Best Regards,

    Terry


    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.

    Tuesday, March 27, 2018 10:04 AM
  • Hi Terry,

    We have tried with compile targeting X64 and .net framework 4.5, but seems like it is also not working .

    I am attaching the console application for your reference.

    https://drive.google.com/drive/folders/1FLlY3QUVp7NRLg4i7hmibVkME_bShXIr?usp=sharing

    Thanks,

    Sakshi

    Monday, April 2, 2018 4:48 AM
  • Hello S Goyal,

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Sorry for any inconvenience and have a nice day! 

    Best Regards,

    Terry


    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.

    Tuesday, April 3, 2018 7:18 AM
  • Sure Terry.
    Tuesday, April 3, 2018 7:23 AM
  • Hi S Goyal.

    Based on the exception, the issue should be relative to no sufficient memory.

    Is this issue could be reproduced every time with this specific document? And to verify this issue, I also suggest that you reboot the PC to clean environment so that there are more memory to see whether this issue could be reproduced.

    Since the issue is not able to reproduce on our side using Word 2016 Version 1803 (Build 9126.2116), would you minding let us know which version of Word are you developing?

    Regards & Fei 



    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.



    Tuesday, April 3, 2018 8:20 AM
    Moderator
  • Hi Fei,

    Yes,We are able to reproduce this issue eveytime with this specific document.Sometimes it is giving"corrupt file exception" as well.We tried by cleaning the PC as well, we are able to reproduce this.

    We are using Word 2007 and Word 2013.In both we are able to reproduce this issue.

    Please note that we tried to break the document in half to see if it is reproducible.In a given document we have Sections "Schedule 4.15" and "Schedule 4.16" , if we remove pages of these section we are not seeing any exception. But if we have pages of these section only, i am able to reproduce the issue.Hope This Helps!

    Thanks,

    Sakshi

    Wednesday, April 4, 2018 5:38 AM
  • Hi Sakshi,

    I was able to reproduce this issue about "corrupt file exception" when I developing with old version Word(version 1708, 16.0.8431.2110). And the issue was fixed when the Word update to the latest version( version 1803, 16.0.9126.2116).

    If you were not using the latest version Word, please update it to the latest version for example using Office 2013 with version 15.0.5015.1000. And please let us know whether the issue was still exits with latest version of Word.

    Regards & Fei


    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, April 4, 2018 9:44 AM
    Moderator
  • Hi Fei,

    Thanks for replying.We have updated our MS Word to 2016 , but we have old version (version 1708, 16.0.8431.2110).Can you please help me out how to update this to new one.

    Thanks,

    Sakshi

    Thursday, April 5, 2018 6:35 AM
  • Hi Sakshi,

    To update Word 2016 to the latest version, we can update it via File->Account->Update Options->Update Now.

    And the available updates are based on the update channel and if you were not use the Monthly Channel we can switch it manually to get the latest update by following the article below:

    How to switch from Semi-Annual Channel to Monthly Channel for the Office 365 suite

    Please feel free to let me know if you still have the problem.

    Regards & Fei


    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.

    • Marked as answer by S Goyal Friday, April 6, 2018 5:01 AM
    Friday, April 6, 2018 1:02 AM
    Moderator
  • Hi Fei,

    We have tried with latest version.And it is working fine.Thanks for the support.

    Thanks,

    Sakshi

    Friday, April 6, 2018 5:01 AM
  • Hi Fei,

    What will be the fix for this in Word 2007 and 2013.According to our requirement, it should work in MS word 2007 and 2013.

    Thanks,

    Sakshi

    Friday, April 6, 2018 5:04 AM
  • Hi Sakshi,

    For the Word 2010, please also try to update it to the latest version to see whether the issue was fixed. Please check the link below for the latest update for Office 2013:

    Update history for Office 2013

    And for the Word 2007, since its support is ending( Support is ending for Office 2007). Continuing to use Microsoft Office 2007 after October 10, 2017 without updating to the most recent version could expose you to serious security risks. Please consider migrating to the latest version of Office.

    Regards & Fei


    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.

    Monday, April 9, 2018 5:14 AM
    Moderator