I have the following script task using C# to refresh the pivot table in Excel in an SSIS package. The package runs well in the Visual Studio as well as the package utility. But when I deployed this package to SSIS Catalog and schedule a SQL Server Agent job, it failed on the script task part with a very generic error message
Exception has been thrown by the target of an invocation
I have researched a couple of other Q&As but our situations differ a lot.
My script task code
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
#endregion
namespace ST_0126969a11e546b3bbde047669039ab5
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        public void Main()
        {
            //Dts.TaskResult = (int)ScriptResults.Success;
            ExcelRefresh(@"C:\\SSIS\\MTD.xlsx");
        }
        private void ExcelRefresh(string Filename)
        {
            object NullValue = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
            excelApp.DisplayAlerts = false;
            Microsoft.Office.Interop.Excel.Workbook Workbook = excelApp.Workbooks.Open(
               Filename, NullValue, NullValue, NullValue, NullValue,
               NullValue, NullValue, NullValue, NullValue, NullValue,
               NullValue, NullValue, NullValue, NullValue, NullValue);
            Workbook.RefreshAll();
            Workbook.Save();
            //Workbook.SaveAs(DestinationPath, NullValue, NullValue, NullValue, NullValue, 
            // NullValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, 
            //NullValue, NullValue, NullValue, NullValue, NullValue);
            Workbook.Close(false, Filename, null);
            excelApp.Quit();
            Workbook = null;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
        }
    }
}
Please help.
 
     
    