0

I am working on an application where I make my system to generate a report as word document. For this I've used microsoft.office.interop.word through nuget package manager. It is running fine locally but when I published my changes on server it started showing me below error:

     "Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied." (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

My system admin made some some admin rights related changes on server and instead of this error I started getting below error

    Object reference not set to an instance of an object

after getting this error I checked with server db and was able to generate file locally but not on test server.

Can anybody suggest me something?

NewbieCoder
  • 377
  • 3
  • 16
  • 2
    Do you actually have Word installed on the server? – GSerg Dec 11 '18 at 13:20
  • That com object requires a full office installation on the server. Did you check for that? – Ross Bush Dec 11 '18 at 13:21
  • Yes. Server has Office installed on it. – NewbieCoder Dec 11 '18 at 13:22
  • @RossBush didn't get. Can you please elaborate. – NewbieCoder Dec 11 '18 at 13:23
  • @NewbieCoder I asked the same question as GSerg. – Ross Bush Dec 11 '18 at 13:24
  • 2
    You probably should have a look at https://support.microsoft.com/en-ca/help/257757/considerations-for-server-side-automation-of-office. On top of explaining why it's not a great idea to have Office on a server, it mentions your error messages too. – GSerg Dec 11 '18 at 13:26
  • 2
    Using `Microsoft.Office.Interop` in a server environment is not officially supported by Microsoft, and is also not recommended as it is very prone to errors (since office is / was never designed for operating on a server side environment). For more information see the following link to the Microsoft Support page: https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office – bassfader Dec 11 '18 at 13:27
  • 2
    @NewbieCoder don't use interop to create Word files, especially on the server. `docx` is a zip package containing XML files. You can create docx files with the Open XML SDK or other libraries – Panagiotis Kanavos Dec 11 '18 at 13:27
  • 1
    @NewbieCoder it's not that Interop isn't supported, it's simply a bad idea. Each request would have to start a *different* Word instance. On the server. If, for any reason, the code failed to properly close that instance it would remain running. And finally, each interop call is an expensive cross-process call. Generating the same file could easily take 100x times longer than using OpenXML – Panagiotis Kanavos Dec 11 '18 at 13:28
  • @PanagiotisKanavos thanks for explaining so nicely. Ok I'll try using openXML for this. – NewbieCoder Dec 11 '18 at 13:32
  • Maybe also note that you don't have to use Office to generate,manipulate office documents, Our company uses Aspose for a lot of these tasks. t doesn't require an offices installation on servers! – Schwarzie2478 Dec 11 '18 at 13:48

0 Answers0