I have a program that runs on a SBS 2008 server which has Office 2007 installed and creates a report in an Excel file that is emailed. I'm using NetOffice to create the Excel file and it works most times. However, it's regularly throwing a File Not Found exception and failing.
The full exception is:
Inner Exception:System.IO.FileNotFoundException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8007007e The specified module could not be found. (Exception from HRESULT: 0x8007007E). at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType) at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType) at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj) at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at NetOffice.COMObject.CreateFromProgId(String progId, Boolean factoryAddObject) Source: NetOffice Stack Trace: at NetOffice.COMObject.CreateFromProgId(String progId, Boolean factoryAddObject) at NetOffice.ExcelApi.Application..ctor(Boolean enableProxyService) at NetOffice.ExcelApi.Application..ctor() at CCDExceptionReport.Program.Main(String[] args) Target Site: Void CreateFromProgId(System.String, Boolean)
If I immediately re-run the program it will always run successfully.
I have tried doing a rebuild all, replacing the files on the server, compiling in VS 2019 and 2017.
I was finally able to get this solved.
I followed the advice about creating a Desktop folder as needed, which is explained here: Why does systemprofile need Desktop folder to open excel file
I used dcomcnfg.exe and set the security for Microsoft Excel Application Properties to include the user which the scheduled task ran as.
Neither worked.
Finally, by fluke, I was double checking the security and I clicked on the Identity tab. I changed it to "The launching user" instead of "The interactive user" and now all my programs that use the NetOffice add in will work via task manager.
I believe that all three elements need to be in place, the Desktop folder, proper security, and proper identity settings.
To get to the security and identity settings I ran dcomcnfg.exe Expanded DCOM Config Right clicked on Microsoft Excel Application Clicked Properties Edited Security tab Edited Identity