1

Code:

ApplicationClass projectApp = new ApplicationClass();

if (projectApp.FileOpen(path, true, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
PjPoolOpen.pjDoNotOpenPool, Missing.Value, Missing.Value, Missing.Value, Missing.Value))
{
    projects = new List<Project>(projectApp.Projects.Cast<Project>());
    foreach (Project project in projects)
    {
        MSProjectProject msProject = new MSProjectProject();

        msProject.Author = project.Author.ToString(); // ERROR HERE
        msProject.Name = project.Name;
    }
}

Exception:

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

Exception 2: (This one does not get caught by the try block)

DisconnectedContext was detected

Transition into COM context 0x265048 for this RuntimeCallableWrapper failed with the following error: The requested object does not exist. (Exception from HRESULT: 0x80010114). This is typically because the COM context 0x265048 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else and cannot process the context transition. No proxy will be used to service the request on the COM component and calls will be made to the COM component directly. This may cause corruption or data loss. To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them.

When I first access the project the exception is thrown. What am I doing wrong?

Also, I'm new to Interop and it bothers me that when I access a file, it opens with office. Isn't there a way to only peek its content and not open it?

Interop Runtime Version: v2.0.50727;

Interop Version: 14.0.0.0;

Project Version: 2013 (15.0.4569.1504);

Matheus Simon
  • 668
  • 11
  • 34
  • which version of interop are you using and which version of project? –  Aug 26 '14 at 15:48
  • Interop Runtime Version: v2.0.50727; Interop Version: 14.0.0.0; Project Version: 2013 (15.0.4569.1504) – Matheus Simon Aug 26 '14 at 15:57
  • Hello, does this happen for all files or just one specific file. The file could be corrupt even if you can open it using the applications. If this works for other files then your file may be corrupt. – joecop Aug 27 '14 at 00:03
  • some files that happen, some files the list of projects is empty, tough it has projects. – Matheus Simon Aug 27 '14 at 13:07

1 Answers1

0

Resolution is simple: Stop using Interop, it is GARBAGE. It's messy, takes forever to process documents, opens the documents before it can process it and sometimes will simply not work and not tell you why, except when it does and you have problems like the above, where nobody can help.

Though MPXJ implements Java inside .NET, it's still better than Interop!

Matheus Simon
  • 668
  • 11
  • 34