When should use EnablePartialTrustCode property?

23 Jun 20261 minute to read

Enable the EnablePartialTrustCode property only in restricted, hosted environments such as Azure App Service. Because, there will be a GDI+ exception thrown while handling meta file images such as emf and wmf formats. When this property is enabled, the images will not be rendered instead of throwing exception.

NOTE

Azure or other sandboxes hosting: set EnablePartialTrustCode = true to bypass EMF/WMF GDI+ exceptions.
Other environments: keep EnablePartialTrustCode = false for full‑fidelity image rendering.

Use the following code snippet to set the EnablePartialTrustCode property

IApplication application = excelEngine.Excel;
application.EnablePartialTrustCode = false; // Setting the EnablePartialTrustCode to false
IApplication application = excelEngine.Excel;
application.EnablePartialTrustCode = false; // Setting the EnablePartialTrustCode to false
Dim application As IApplication = excelEngine.Excel
application.EnablePartialTrustCode = False ' Setting EnablePartialTrustCode to False