We have code in our library to optionally create a PDF file by creating a DOCX and then using interop calls, calling Word to open the DOCX and save it as a PDF. (I know this is not a great idea, but it's the least bad option when one needs a pixel perfect match of the output.)
This works great when running as an app or plain old server. But it is failing in an ASP.NET app, I think due to permission issues. What do I have to do so that an ASP.NET app can call Word (and Excel & PowerPoint) via interop?
Here is the exception stack. It's a permissions issue pretty clearly - but what needs to be set?
2020-07-13 08:23:42,564 [58] ERROR OfficeOutputBuilder.WindwardOutputBuilder - buildReport() failedSystem.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
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.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at OfficeOutputBuilder.WordOutputBuilder.Convert(Application word, ProcessPdf process, String inputFile, String outputFile)
at OfficeOutputBuilder.WindwardOutputBuilder.buildReport(ProcessReport report, Object application, InputStream sourceDocument, OutputStream generatedDocument)
System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
StackTrace: 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.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at OfficeOutputBuilder.WordOutputBuilder.Convert(Application word, ProcessPdf process, String inputFile, String outputFile)
at OfficeOutputBuilder.WindwardOutputBuilder.buildReport(ProcessReport report, Object application, InputStream sourceDocument, OutputStream generatedDocument)System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
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.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at OfficeOutputBuilder.WordOutputBuilder.Convert(Application word, ProcessPdf process, String inputFile, String outputFile)
at OfficeOutputBuilder.WindwardOutputBuilder.buildReport(ProcessReport report, Object application, InputStream sourceDocument, OutputStream generatedDocument)
2020-07-13 08:23:42,569 [58] WARN RESTfulEngine.BusinessLogic.ReportGenerator - Generate(template, cc346f0d-8613-46a2-ad1e-d0c686f40bcf)net.windward.env.OutputLimitationException: Error code: 3, details: Error using external output builder: Error code: 7, details: buildReport error Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
net.windward.env.OutputLimitationException: Error code: 3, details: Error using external output builder: Error code: 7, details: buildReport error Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
StackTrace: at net.windward.xmlreport.ProcessReport._processComplete(Boolean batchMode)
at net.windward.xmlreport.ProcessReport.processComplete()
at net.windward.api.csharp.Report.ProcessComplete()
at RESTfulEngine.BusinessLogic.ReportGenerator.GenerateDocument(Template template) in C:\git\Jenova\restfulengine\RESTfulEngine\BusinessLogic\ReportGenerator.cs:line 67
at RESTfulEngine.BusinessLogic.ReportGenerator.Generate(Template template) in C:\git\Jenova\restfulengine\RESTfulEngine\BusinessLogic\ReportGenerator.cs:line 84
INNER EXCEPTION: net.windward.env.OutputLimitationException: Error code: 7, details: buildReport error Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
StackTrace: at OfficeOutputBuilder.WindwardOutputBuilder.buildReport(ProcessReport report, Object application, InputStream sourceDocument, OutputStream generatedDocument)
at net.windward.xmlreport.ProcessReport._processComplete(Boolean batchMode)
INNER EXCEPTION: System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
StackTrace: 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.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at OfficeOutputBuilder.WordOutputBuilder.Convert(Application word, ProcessPdf process, String inputFile, String outputFile)
at OfficeOutputBuilder.WindwardOutputBuilder.buildReport(ProcessReport report, Object application, InputStream sourceDocument, OutputStream generatedDocument)net.windward.env.OutputLimitationException: Error code: 3, details: Error using external output builder: Error code: 7, details: buildReport error Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
User contributions licensed under CC BY-SA 3.0