Cascade Skyline - with Microsoft Logo and Project Support header - author Brian Smith

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

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

  • Comments 8

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

Leave a Comment
  • Please add 8 and 1 and type the answer here:
  • Post
  • 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

  • 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?

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

  • I created a ms project web part to display custom formula using following approach.

    1. Create Project.Application object

    2. Call FieldConstantToFieldName

    3. Every thing works fine on x86

    But which i deployed the same on x64 the web stop loading and give error of deserialization.

    Can you suggest some solution

  • Brian,

    You're a rock star!!! This post really helped us with a defect we kept experiencing.

    Thanks,

    Vivien

  • Hi Brian,

    Is there a hot fix available for Windows 7?

    Thanks,

    Asit

  • Hi Brian,

    Has this been fixed?

    Thanks,

    Asit

  • Hi Asit, as reported above a hotfix was released in April 2008.  I assume this was also fixed before release of Windows 7 and 2008 R2, but haven't tried on these platforms.  See blogs.msdn.com/.../now-fixed-comexception-on-x64-platforms-when-automating-office-clients-via-the-primary-interop-assembly-pia.  I will see if I can fidn out more.

    Best regards,

    Brian.

Page 1 of 1 (8 items)