Click here to Skip to main content
15,790,807 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am writing a web application in C# to read and write into MS Project file. When I create an instance of Microsoft.Office.Interop.MSProject.Application, I get System.OutOfMemory Exception. I get this exception on while executing the web page from IIS. On localhost, it works fine.

Regards,
UU

What I have tried:

I tried executing the application from localhost, it works. It doesn't work over the IIS.
Posted
Updated 11-Jul-16 22:45pm
Comments
Suvendu Shekhar Giri 12-Jul-16 3:07am    
Not enough information to workout.
kakkkosa 13-Jul-16 2:24am    
below is my code

Microsoft.Office.Interop.MSProject.Application app = new Microsoft.Office.Interop.MSProject.Application();

app.FileOpen(filename, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, MSProject.PjPoolOpen.pjPoolReadWrite, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
app.Visible = false;
MSProject.Project proj = app.ActiveProject;

proj.ProjectFinish = projenddate;
proj.Tasks[1].Finish = projenddate;



app.FileSaveAs(filename, MSProject.PjFileFormat.pjMPP, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);


app.Quit(Microsoft.Office.Interop.MSProject.PjSaveType.pjSave);
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
app = null;
GC.Collect();



the exception comes in the first line itself.. Let me know if you I can provide any more details

1 solution

Microsoft office programs are not safe for use in Windows services / IIS. You should use the Microsoft.Office.Interop library only when you have a program with a GUI running in a user session.
Try to find a library which can work with the MS Project files without calling MS Project.
[Edit]
See also: https://support.microsoft.com/en-us/kb/257757[^]
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
By the way, "OutOfMemoryException" is often just an erroneously translated error of a non-managed component.
[/Edit]
 
Share this answer
 
v2
Comments
kakkkosa 13-Jul-16 2:26am    
I am not running a windows service. It is a web application. It has a UI. I get the exception when I run the application from the server. It works fine when I execute from localhost.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900