|Could not load file or assembly 'PDFNet.dll' ' when using PDFNet for .NET 4.x||Mirko||3/19/13 4:07 AM|
Hi, I'm trying to develop a sample, blank web application including the PDFNet x64 dll. So I create the app from the standard VS2012 web form template and run it. Then I try to add the PDFNet dll.
If I run the test web app on .NET 3.5 no problem. If I run it in .NET 4 or 4.5 I get this error:
=== Pre-bind state information ===
[ConfigurationErrorsException: Could not load file or assembly 'PDFNet' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
[HttpException (0x80004005): Could not load file or assembly 'PDFNet' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
I have already searched a lot on the web and in this group, and I have already tried the solutions proposed for instance in
or others similar, but to no avail. I'm running a Windows 8 machine x64 with all versions of .NET up to 4.5 installed, and I DO have the Microsoft Visual C++ 2010 x64 Redistributable installed on my PC. I have also tried copying both the msvcr100.dll and msvcp100.dll to the output bin folder, but I still get this error. I then thought that maybe it was the fault of VS2012 development server which runs in x86 mode, so I have set up a website on IIS and run it from there on x64, but still the same result. I am a bit bereft, does anybody have any idea? Thanx.
|Re: [PDFNet] Could not load file or assembly 'PDFNet.dll' ' when using PDFNet for .NET 4.x||Ryan||3/19/13 10:33 AM|
The PDFNet x64 library is for targeting frameworks 2.0 - 3.5. Since your building .net 4 or 4.5, you should use PDFNet for .Net 4.
You can see the libraries and the frameworks they target at this link
If there is some reason to use the .Net 2 assembly, the following article might help.
PDFTron Systems, Inc.
CONFIDENTIALITY NOTICE: This message (and any attachment to it) is intended only for the use of the individual or entity to which it is addressed in the header, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. Any reproduction, distribution, modification or use of the contents of this message (and any attachment to it) by any individual or entity other than the intended recipient is prohibited. If you have received this communication in error, please notify us immediately and delete the original.
|Re: Could not load file or assembly 'PDFNet.dll' ' when using PDFNet for .NET 4.x||Vincent Ycasas||3/19/13 11:41 AM|
In addition to what Ryan said, if you need to use the .NET CLR 2.0 assembly, you will need to properly configure your IIS's application pool. In Windows 7 or later, all IIS application pools default to using .NET CLR 4.0. Which means that if you did not change any of these settings you will need to grab either PDFNetDotNet4 or PDFNet64DotNet4 assemblies.
|Re: Could not load file or assembly 'PDFNet.dll' ' when using PDFNet for .NET 4.x||Mirko||3/20/13 12:48 AM|
Hi Vincent and thanks to both you and Ryan.
I had first made a test with the PDFNet64 that you are talking about, for .NET < 4 and it works fine for .NET < 4 if I run it from VS development server.
But then I had also tested the PDFNet64DotNet4 dll in IIS and was still getting the same result.
Here are the steps I did in detail:
- created a new Web Form Project in Visual Studio 2012, .NET 4
- copied the whole project directory to a different location than the 'Projects' default directory to avoid IIS permission problems
- set up iis to point to that directory. The Application Pool has .NET 4.0.30319 version
- start the web app from Visual Studio (set to use IIS instead of VS development server) on port 84 (http://localhost:84), no problem
- stop the web app from Visual Studio
- Add reference to PDFNet.dll (taken from http://www.pdftron.com/downloads/PDFNet64DotNet4.zip)
- start the web app from Visual Studio, I get the error.
I repost the stack trace, in case I had taken one from a previous test in my previous post.
Server Error in '/' Application.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'PDFNet' or one of its dependencies. An attempt was made to load a program with an incorrect format.
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'PDFNet' could not be loaded.
LOG: User = IIS APPPOOL\test
WRN: Assembly Name: PDFNet | Domain ID: 10
LOG: Appbase = file:///C:/Sites/WebApplication4/WebApplication4/
LOG: Initial PrivatePath = C:\Sites\WebApplication4\WebApplication4\bin
LOG: Using application configuration file: C:\Sites\WebApplication4\WebApplication4\web.config
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/3f5814f6/8a010b0d/PDFNet.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/3f5814f6/8a010b0d/PDFNet/PDFNet.DLL.
LOG: Attempting download of new URL file:///C:/Sites/WebApplication4/WebApplication4/bin/PDFNet.DLL.
As stated previously, I do have the Microsoft Visual C++ 2010 x64 Redistributable - 10.0.40219 regularly installed on my machine.
Any further ideas or questions are greatly appreciated.
Il giorno martedì 19 marzo 2013 19:41:12 UTC+1, Vincent Ycasas ha scritto:
|Re: Could not load file or assembly 'PDFNet.dll' ' when using PDFNet for .NET 4.x||Vincent Ycasas||3/20/13 11:18 AM|
Did you install ASP.NET 4.5 support for your IIS? Please verify this by doing the following:
1.) Open Control Panel.
2.) Go to Programs and Features.
3.) Click Turn Windows features on or off.
4.) In the Windows Features windows, expand Internet Information Services.
5.) Expand World Wide Web Services, then expand Application Development Features.
6.) Make sure that ASP.NET 4.5 is checked if using .NET CLR 4.0 or ASP.NET 3.5 is checked if using .NET CLR 2.0.
7.) Click OK. You may be asked to restart the system.
Once that is set, make sure your web application is using .NET 4.0 application pool as mentioned before. Furthermore, if you wish to use 64-bit PDFNet, you will need to disable the "Enable 32-bit Applications" options. To do this:
1.) Open the IIS Manager.
2.) Open the Application Pools list.
3.) Select the Application Pool being used, then right-click, select Advanced Setings...
4.) Find the Enable 32-bit Applications in the drop down list and make sure it is set to False when building a 64-bit web application.
Another important reminder to keep note of is your project settings in Visual Studio. By default, any new projects created will target "Any CPU" platform. Leaving it at that can cause some architecture mismatch issues. When developing with PDFNet, it is always a good idea to set the platform target to exactly match the version of PDFNet library. If you wish to develop with 64 bit PDFNet, make sure that the project's platform target is set to "x64". Likewise with 32 bit PDFNet.
To change the platform target:
1.) Open the project in Visual Studio.
2.) Right-click on the project, then select Properties.
3.) Go to Build tag, then find the Platform target drop down.
4.) Set the Platform target to match the PDFNet version you are using.
5.) Save the settings and rebuild the project.
We have verified that all of these settings should be able to run your application with PDFNet64DotNet4. If you run the following code snippet below and you get the same info as the screenshot attached, then your system should be setup to develop with PDFNet64DotNet4.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DotNet45.Default" %>
|Re: Could not load file or assembly 'PDFNet.dll' ' when using PDFNet for .NET 4.x||Mirko||3/21/13 2:33 AM|
thank you, yes i had ASP.NET 4.5 correctly installed, and resetting the 'Enable 32-bit application' to false in the Application Pool settings solved it. Somehow this conflicted with the x64 library, thus causing the problem. I had probably set it to true during other tests. I also had then successfully tried to use the 32-bit dll (instead of the x64 dll) re-enabling this 'Enable 32-bit application' IIS application pool settings.
Thank you for your support
Il giorno martedì 19 marzo 2013 12:07:35 UTC+1, Mirko ha scritto: