Welcome to MSDN Blogs Sign in | Join | Help

COMException on x64 platforms when automating the Project client via the Primary Interop Assembly (PIA)

***UPDATE*** Hotfix now available - http://blogs.msdn.com/brismith/archive/2008/11/18/now-fixed-comexception-on-x64-platforms-when-automating-office-clients-via-the-primary-interop-assembly-pia.aspx  

You may see this error when using the CodePlex Test Data Population sample for creating project data using the WinProj tab, or just using your own code to automate winproj.exe (the Microsoft Office Project Professional 2007 client application).  It is only a problem with the object model interaction and not an issue with PSI calls.  It is the Tasks.Add() method which is the trigger for the problem, and it will work just fine on x86, but fails on x64.

Currently the x64 platforms do not support more than 1024 methods on an object (which comes down to around 1017 once the COM standard methods are deducted) and the Tasks object has a lot of methods.

The error is:

Error HRESULT E_FAIL has been returned from a call to a COM component. System.Collections.ListDictionaryInternal.

One work around we have found is re-writing to avoid using the Tasks method.  So the following code:

protected void Page_Load(object sender, EventArgs e)
{
string filename = "c:\\test.mpp";
ApplicationClass a = new ApplicationClass();
a.FileNew(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Microsoft.Office.Interop.MSProject.Project p = a.ActiveProject;
 p.Tasks.Add("test", Type.Missing);
p.SaveAs(filename, PjFileFormat.pjMPP, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, "MSProject.mpp.9", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
a.Quit(PjSaveType.pjDoNotSave);
lblfilename.Text = filename;
}

could be re-written as:

protected void Page_Load(object sender, EventArgs e)
{
MSProject.Application objAppProject;
MSProject.Project objProject;
string filename = "c:\\test.mpp";
objAppProject = new Microsoft.Office.Interop.MSProject.Application();
objAppProject.FileNew(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
objAppProject.EditGoTo(1, Type.Missing);
objAppProject.SetTaskField("Name", "Test", true, Type.Missing, 1, Type.Missing);
objProject = objAppProject.ActiveProject;
objProject.SaveAs(filename, MSProject.PjFileFormat.pjMPP, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, "MSProject.mpp.9", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
objAppProject.Quit(MSProject.PjSaveType.pjDoNotSave);
lblfilename.Text = filename;
}

and would work in both x86 and x64 environments.

This is currently being worked on by the Windows teams and we are anticipating a fix.

Published Friday, February 15, 2008 11:11 PM by BriSmith

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Wednesday, October 22, 2008 12:23 AM by FuzzyLogic

# re: COMException on x64 platforms when automating the Project client via the Primary Interop Assembly (PIA)

Hi Brian,

Thanks very much for tackling this specific problem & making it available on the net.

Finally, after lots of frustration & wondering what I was doing wrong when other Tasks.Add examples worked, I found this URL via Google & that helped fix my problem.

Regards

Monday, November 17, 2008 1:35 AM by Anton

# re: COMException on x64 platforms when automating the Project client via the Primary Interop Assembly (PIA)

Hi Brian,

Sorry for my English

On x64 I have following error in my code:

MSProject.Application pjApp = new MSProject.Application();

MSProject.Project project = pjApp.ActiveProject;

pjApp.FileOpen(@"D:\sample.mpp", true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,

Type.Missing,Type.Missing, Type.Missing, Type.Missing,

PjPoolOpen.pjPoolReadWrite, Type.Missing, Type.Missing,

Type.Missing, Type.Missing);

pjApp.Visible = true;

foreach (MSProject.Task task  in project.Tasks)

{

MessageBox.Show(task.Name.ToString());

}

pjApp.Quit(PjSaveType.pjDoNotSave);

Can you help me to run on x64?

Monday, November 17, 2008 7:02 PM by BriSmith

# re: COMException on x64 platforms when automating the Project client via the Primary Interop Assembly (PIA)

Hi Anton,

There is now a hotfix to address this issue - http://support.microsoft.com/kb/950136/en-us.

I hope this helps you.

Best regards,

Brian.

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker