Azure Fuction - Could not load file or assembly 'office'.

Baskar G 2 Reputation points
2022-07-13T14:38:13.547+00:00

Hi Team,

In my Azure functions i am using "Microsoft.Office.Interop.Excel". After using in my code. i am getting below error

System.Private.CoreLib: Exception while executing function: : Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.

i have added the dll from this location "C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\15.0.0.0__71e9bce111e9429c".

But still getting same error.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,398 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Pierre-Luc Giguere 1,076 Reputation points
    2022-07-13T18:42:30.493+00:00

    Hi,

    "Microsoft.Office.Interop.Excel" cannot be used without having Office installed.

    Installing Office in App Service is not supported

    You can either host your function on a VM or use something like OpenXML (https://github.com/OfficeDev/Open-XML-SDK) with ClosedXML (https://github.com/ClosedXML/ClosedXML) to edit Excel files.

    (this is based on my knowledge by july 13th 2022)

    0 comments No comments

  2. MughundhanRaveendran-MSFT 12,481 Reputation points
    2022-07-14T09:37:19.513+00:00

    Hi @Anonymous ,

    Thanks for reaching out to Q&A forum.

    Microsoft.Office.Interop.Excel is a part of Office library and it needs the complete office suite to work. Unfortunately installing and running office applications/libraries on a server is not supported. Please refer to this article that talks about the server side automation of office : https://support.microsoft.com/en-us/topic/considerations-for-server-side-automation-of-office-48bcfe93-8a89-47f1-0bce-017433ad79e2

    As mentioned in the document, you can use the open XML sdk at the function level. Alternatively, you can use Microsoft Graph API for Excel, I would suggest you to use Graph API as this is where the active development is happening. When you are using Graph API, it becomes easier to work with other Office apps such as outlook and sharepoint. Graph API is a single endpoint to access all the office resources.

    I hope this helps! Feel free to reach out to me if you have any further queries or concerns.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.