I was once deploying a project (that involves Open Xml operations) on Azure. The project would run fine locally on my machine and but the code just wouldn’t run. After lots of scratching, I discovered the 2 problematic situations faced most widely that leads to this problems. The root cause here is that Azure doesn’t support the OpenXml operation directly since the required dlls are not available on Azure. The solution to the problem is changing the configuration of your project references, so whenever you get stuck in this problem, just check out which of the following situations apply to you and make the necessary changes to make your code work.

Scenario 1: The excel operations are performed in your main web project (i.e. the project being deployed on the cloud):

  1. Expand the project’s “References” folder
  2. Select the “DocumentFormat.OpenXml” and “WindowsBase” dlls
  3. Right click on them and then select “Properties”
  4. Set “Copy Local = True
Scenario 2: The Open Xml operations are being done inside a dll and then this custom dll is being referenced in your web project. If this is the case, do the following:
  1. Add References to “DocumentFormat.OpenXml” and “WindowsBase” dll in your main web project
  2. In your web project, expand the “References” folder
  3. Select your custom dll and the “DocumentFormat.OpenXml” and “WindowsBase” dlls
  4. Right click on them and then select “Properties”
  5. Set “Copy Local = True
Rebuild your project and deploy again, and this time it’ll work!
Advertisements