I have a VSTO app built in Visual Studio that runs this block of code:
using MSP = Microsoft.Office.Interop.MSProject;
using VB = Microsoft.VisualBasic;
if (IsMSProjectIsOpen())
{
pApp = (MSP.Application)VB.Interaction.GetObject(Class: "MSProject.Application");
}
else
{
pApp = CreateMSProjectApp();
}
This has always worked but it was failing on one of my user's computers today for some reason.
I ran a test on that computer using the Microsoft Project VBA editor to try to set the Application object using the GetObject method:
Sub Test()
Dim app As MSProject.Application
Set app = GetObject(Class:="MSProject.Application")
End Sub
Normally the app object would get set just fine and look like this in the locals window:

for some reason, the computer I'm testing on using the exact same code sets the app object so it's not null but when you expand the node in the locals window it shows No Variables:
And when you try to access any of it's properties or methods it throws an error:
What's going on here?


The Office message pump retrieves the message and dispatches it to a hidden OLE window where the call is un-marshalled and executed. However, before executing the call, COM first checks with Office to ensure that it is actually able to handle the call. In some cases, the call could result in an undesirable case of reentrancy (such as when Office is in a modal state or it is in the middle of a long operation like a conversion). In those cases, Office can tell COM that it is too busy to handle the call, in which case
RPC_E_CALL_REJECTEDis returned to the caller. In your case, the failure is being converted by COM interop to an exception.To overcome this, Microsoft recommends to disable the COM Add-ins.
Note, when two applications are run under different security contexts in Windows you will not be able to connect to the running instance. Your choice is to create a new instance under the same security context and automate it then.