Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# InteropServices
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 13-Jun-11 18:01pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You may apply how to fix corrupt ms project file file format is not valid
 
Article [spam link removed] can solve your trouble
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 17 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100