Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Use the Spire component to throw an exception The type initializer for & # 39

Shulou Source: shulou.com Published: 2022-06-01 01:57:23 10月01日 Update

Use the Spire component to throw an exception The type initializer for 'spr857' threw an exception

I tried to convert an Excel document to an PDF document using the free Spire.Xls component, and threw the exception "The type initializer for 'spr857' threw an exception" when I executed the second line of code below, which is to load the document.

Workbook workbook = new Workbook ()

Workbook.LoadFromFile ("D:\\ sample.xlsx")

Workbook.SaveToFile ("D:\\ sample.pdf", Spire.Xls.FileFormat.PDF)

This problem bothered me for a long time, and I couldn't find its solution on the Internet. Later, I visited the forum of E-iceblue Company and found its solution. The technical staff of E-iceblue Company replied: please make sure Spire.pdf.dll file is placed in the same location as Spire.xls.dll.

According to this meaning, I have tried two solutions, both of which can solve this problem. I would like to share them here:

Option 1, copy the Spire.pdf.dll file in the Spire.Xls package to the same directory as Spire.Xls.dll.

Scenario 2, import Spire.XLS.dll and Spire.Pdf.dll into the project as Reference at the same time.

The result of the conversion is perfect:

Original Excel:

The converted PDF:

While using Spire.Xls, I also encountered the same problem when I tried to use free Spire.Doc to convert Word documents to PDF documents, and the above two schemes also apply to Spire.Doc components.

Tags: Solutions documents components problems attempts same company at the same time solutions original two that is people code meaning technology copies files directories results Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno macOS Shulou Technology MariaDB