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.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.