Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am trying to open an ms project file using the code below. The closing of the file is done manually but I want to handle the event to be able to cleanup the resources needed to be cleanup up. With this code, I have no problem when trying to open the file for the first time.

I am having problems when I manually close the file and try to call OpenReport (to reopen the file). I am getting the error:

Unable to cast COM object of type 'Microsoft.Office.Interop.MSProject.ApplicationClass' to interface type 'Microsoft.Office.Interop.MSProject._MSProject'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020AFF-0000-0000-C000-000000000046}' failed due to the following error: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA).


A different error is thrown when I try to call OpenReport without closing the file manually.

COM object that has been separated from its underlying RCW cannot be used.

protected override void OpenReport(string filename)
{
    //projectApp is a Microsoft.Office.Interop.MSProject.ApplicationClass
    projectApp.FileOpenEx(filename, .Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, PjPoolOpen.pjDoNotOpenPool, Type.Missing, Type.Missing, Type.Missing);

    projectApp.Visible = true;
}


Thanks in advance.
Posted

1 solution

You may apply how to fix corrupt ms project file file format is not valid

Article [spam link removed] can solve your trouble
 
Share this answer
 
v2

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