Out of Memory failure automating VSTO Powerpoint API

允我心安 提交于 2019-12-12 20:43:08

问题


I am using the VSTO Powerpoint API to automate the creation of Powerpoint files. What I have found is that using the most basic call to create a Powerpoint file from a web application on a Windows 7 system causes an out of memory error (other VSTO calls that manipulate an open file also fail):

PowerPoint.Presentation presentation = _ppPresentations.Add(Office.MsoTriState.msoTrue);
        string outputDirectory= getOutputDirectory();
        presentation.SaveAs(outputDirectory+ "\\CreateSlideTestOutput.pptx",
                            PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Office.MsoTriState.msoTrue);

The error that I receive is "Insufficient Memory" at whatever VSTO API call is being made to manipulate a file (for instance, saving or adding a slide to a powerpoint).

However, I found that if I run the same code in a unit test, or as a user executable (.exe), I have no problems adding content, manipulating and saving Powerpoint files.

But then, when I tried to create a Windows service to automate the same code used in my user executable, I am receiving an Insufficient Memory error again. I can set a breakpoint in my service and see that it is failing on the exact same VSTO API calls that failed when called from my web application.

Does anyone have an explanation why the user executable thread can execute VSTO API calls without any issue what so ever (and no observable jump in memory) whereas my App pool thread, or Windows service thread always runs into Insufficient Memory errors?


回答1:


http://support.microsoft.com/kb/257757

Automating Office documents (with the Interop .dlls) without a user context isn't "stability" supported by MS. They advise to use another solution like the OpenXML SDK:

http://www.microsoft.com/en-us/download/details.aspx?id=5124



来源:https://stackoverflow.com/questions/16390358/out-of-memory-failure-automating-vsto-powerpoint-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!