2

I'm having a strange issue related to talking to Microsoft.Office.Interop.MSProject. I'm using MSProject 2013 with Office.DLL v15 and Microsoft.Office.Interop.MSProject.DLL v15. We are updating our program, which sync's data between our product and project to use the latest DLLs, to support MSProject 2013. I'm going to attach images of code so you can see what I'm seeing.

I have a local variable that is assigned the value of the Project using the Interop class.

'Assembly Microsoft.Office.Interop.MSProject C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.MSProject.dll'

I'm looking for a value from Project.ProjectStart, which when I use the watch window shows a value.

Watch Window Shows Value for Project.ProjectStart = valid value

BUT, when the code actually executes, the value of Project.ProjectStart = Null.

Scope Shows Value for Project.ProjectStart = Null

Things I've checked:

  • Make sure that all projects build to x86 and that the Project I'm using is x86. However, I am on a 64bit Win7 machine. Could this be a x86 vs x64 dll issue?

This is a stumper. I'll buy you a Mountain Dew if you can help me out ;)

ANSWER FOUND!!!

This solution applies to all Microsoft.Office.Interop similar issues across all office apps.

Here is a thread I started on MSDN that found me my answer. http://social.msdn.microsoft.com/Forums/office/en-US/079ed850-b8ee-4d5f-93ad-a31f6d9c2607/microsoftofficeinteropmsproject-throwing-systemnotimplementedexception?forum=officegeneral#079ed850-b8ee-4d5f-93ad-a31f6d9c2607

Did you try to use the late binding technology (see Type.InvokeMember) for getting the value? Does it help? YES! is and answer. Type.InvokeMember works.

Here is a code snippet that I now use to access these members.

    public DateTime LateBindProjectStart()
    {
        try
        {
            if (project != null)
            {
                if (project is Microsoft.Office.Interop.MSProject.Project)
                {
                    DateTime dtStart = (DateTime)(typeof(Microsoft.Office.Interop.MSProject.Project).InvokeMember(
                        "ProjectStart",
                        BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public,
                        null,
                        project,
                        null));
                    return dtStart;
                }
                else
                    return DateTime.MinValue;
            }
            else
                return DateTime.MinValue;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
John Kocktoasten
  • 915
  • 7
  • 12
  • Learning some good stuff as I dig into this. The code in this example is being run from a background worker thread. Backgroundworker is a Multithread Apartment, http://stackoverflow.com/questions/4685237/how-can-i-make-a-background-worker-thread-set-to-single-thread-apartment and COM interop objects are Single Thread Apartments. http://msdn.microsoft.com/en-us/library/8sesy69e(v=vs.100).aspx So that might be having some impact. This is happening on my machien which is a quad core, so could be a threading issue. – John Kocktoasten Jul 31 '14 at 22:51
  • The other possiblity, is that when I look at the mspData.Project.ProjectStart in the watch window, its shows that is it is a dynamic {system.DateTime} so there is something to investigate there as well. The fun continues! – John Kocktoasten Jul 31 '14 at 22:53
  • What is the `mspData` object? Can you retrieve any other properties of `localProject`? – Rachel Hettinger Aug 04 '14 at 22:25

0 Answers0