none
MSProject Interop with Azure Function Advice RRS feed

  • Question

  • Hello, looking for advice on where to find more information or post a request to figure out a point issue with using MS Project Interop with Azure function.  Simplified code below to illustrate the issue: works fine in VS Console app, same line of code fails when using Azure function to trigger code on local machine:

    PURPOSE:

    I'm working on a utility that lets a MSProject user upload a .MPP file to an Azure function which is to open the file and do some further processing (export to Excel etc.).  
    Using the MSProject Interop via:

    APPROACH

    using Microsoft.Office.Interop.MSProject;

    after loading it via Project | Add Reference to add Office\PIA\Office15\Microsoft.Office.Interop.MSProject.dll to my VS 2019 solution, 
    executing the following code generates a runtime error:

                Microsoft.Office.Interop.MSProject.ApplicationClass projectApp = new Microsoft.Office.Interop.MSProject.ApplicationClass();
                projectApp.FileOpen("C:\\temp\\10DLC.mpp", 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);

    because generates a runtime error because this returns a null for projectApp.  The error returned by the function is:

    System.Private.CoreLib: Exception while executing function: Function1. ConvertMPP: Object reference not set to an instance of an object.

    I then tried the exact same code in a Console application, and it works fine every time.   Below is the full code I run for MSProject:

    CODE CAUSING THE ISSUE

    Microsoft.Office.Interop.MSProject.ApplicationClass projectApp = new Microsoft.Office.Interop.MSProject.ApplicationClass();
    projectApp.FileOpen("C:\\temp\\10DLC.mpp", 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);

    // Get the active project and start / finish dates used to format the output 
    Project proj = projectApp.ActiveProject;

    log.LogInformation($"{proj.Tasks.Count} # of tasks in the project");

    above generates the runtime error when accessing the property Tasks.Count

    Any help on where Azure / MS Project resources are available or any other sites that may address similar issues is greatly appreciated.

    Sunday, September 29, 2019 5:57 PM

All replies

  • To save others the same difficulty, I did find a solution which was to not use Interop at all!   After much searching, I found a nuget package that you can install in Visual Studio via 

    Install-Package NetOffice.MSProject -Version 1.7.4.4

    (note above version may be new so you need to search nuget gallery)

    and viola, the exact same code worked perfectly using the class Application() class that comes with this package.  It fixes a problem that was a hard stop for me and so hopefully it helps someone else.

    Monday, September 30, 2019 4:27 AM