简体   繁体   中英

PdfiumViewer Pdfium Exception - VS2017 Created Project must be .Net 4.0 and then upgrade to any higher versions

VS2017 ver 15.9.3

NuGet Packages PdfiumViewer version="2.13.0.0"

PdfiumViewer.Native.x86_64.v8-xfa version="2018.4.8.256"

Test Scenario - Load PDF file with PdfiumViewer

  1. Create Project1: Target Framework = .Net Framework 4. Program runs successfully.
  2. Change Project1 to any higher Framework - 4.5, 4.5, 4.6 ... 4.72 Program runs successfully

3. Create Project2: Target Framework = .Net Framework 4.7.2 or any other FW 4.5, 4.5, 4.6 ( ** NOT FW 4 ).
Error Message: $exception {"An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"} System.BadImageFormatException

  1. Change Project2 to FW = 4. Program runs successfully.
  2. Change Project2 to any higher Framework - 4.5, 4.5, 4.6 ... 4.72 Program runs successfully

Code

Error Message: $exception {"An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"} System.BadImageFormatException

  private void button1_Click(object sender, EventArgs e)
  {
     string pdf = @"D:\PDF\TestFile.pdf";

     try
     {
        var document = PdfiumViewer.PdfDocument.Load(pdf);   // *** Exception  ***
        MessageBox.Show("OK");
     }
     catch (Exception ex)
     {
        MessageBox.Show(ex.Message);
     }
  }

==============

Help is appreciated.

Add both the x86 and x64 folders containing pdfium.dll to the Debug/Release directories, that should be the way. In case you don't know where to find them, run the PdfiumViewer.Demo project from PdfiumViewer Github , you will find them inside the bin folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM