In our .Net application, Excel is getting run. Is there any way to avoid calling Activator.CreateInstance() when starting an Excel instance? new Excel.Application() causes it to be called.
This is the code which opens excel :
public void OpenExcel(string filePath, Action beforeCloseAction, Action beforeSaveAction = null)
{
_excelApp = new Application
{
DisplayAlerts = false,
WindowState = XlWindowState.xlMaximized,
Visible = false,
};
_onBeforeSaveCall = beforeSaveAction;
_excelApp.WorkbookBeforeSave += WorkbookBeforeSave;
_onBeforeCloseCall = beforeCloseAction;
_excelApp.WorkbookBeforeClose += WorkbookBeforeClose;
_excelWorkbooks = _excelApp.Workbooks;
SetExcelWorkbook(_excelWorkbooks.Open(filePath));
_excelWorkbook.Saved = true;
}

Have you run a profiler so that you know where the performance issues lie? I’d be very surprised if the call to Activator.CreateInstance was a performance bottleneck in your application. Presumably you will not be creating many Excel instances per second, but rather one instance on start up. Whether this is done by Activator.CreateInstance or not should make little difference.