Could not load file or assembly 'PDFNet.dll' ' when using PDFNet for .NET 4.x

Showing 1-6 of 6 messages
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:

----------------------------
Could not load file or assembly 'PDFNet' or one of its dependencies. An attempt was made to load a program with an incorrect format.

=== Pre-bind state information ===
LOG: User = IIS APPPOOL\.NET v4.5
LOG: DisplayName = PDFNet
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: PDFNet | Domain ID: 5
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Sites/WebApplication2/WebApplication2/
LOG: Initial PrivatePath = C:\Sites\WebApplication2\WebApplication2\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Sites\WebApplication2\WebApplication2\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/90a438de/bb3b334f/PDFNet.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/90a438de/bb3b334f/PDFNet/PDFNet.DLL.
LOG: Attempting download of new URL file:///C:/Sites/WebApplication2/WebApplication2/bin/PDFNet.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.


Stack Trace:


[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.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[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.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +258
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[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.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873784
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18033
----------------------------

I have already searched a lot on the web and in this group, and I have already tried the solutions proposed for instance in

https://groups.google.com/forum/?fromgroups=#!newtopic/pdfnet-sdk/pdfnet-sdk/jXBDWdV0_NQ

or

https://groups.google.com/forum/?fromgroups=#!newtopic/pdfnet-sdk/pdfnet-sdk/OqVycSlOlB0

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.




--
You received this message because you are subscribed to the "PDFTron PDFNet SDK" group (http://www.pdftron.com/pdfnet/forum.html).
---
You received this message because you are subscribed to the Google Groups "PDFTron PDFNet SDK" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdfnet-sdk+...@googlegroups.com.
To post to this group, send email to pdfne...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Best Regards,

Ryan Barr
Software Developer
PDFTron Systems, Inc.
Tel: 1-604-730-8989
Fax: 1-604-676-2477

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.

Could not load file or assembly 'PDFNet' or one of its dependencies. An attempt was made to load a program with an incorrect format.
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.

Source Error:

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.



=== Pre-bind state information ===
LOG: User = IIS APPPOOL\test

LOG: DisplayName = PDFNet
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: PDFNet | Domain ID: 10

WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Sites/WebApplication4/WebApplication4/
LOG: Initial PrivatePath = C:\Sites\WebApplication4\WebApplication4\bin

Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Sites\WebApplication4\WebApplication4\web.config

LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
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.

ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.


Stack Trace:


[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.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[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.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +258
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[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.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873784
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18033
---------------------------------

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.
Thank you

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" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <h1>
        Powered by PDFNet v<%=pdftron.PDFNet.GetVersion().ToString() %>
    </h1>
    <br />
    <h2>
        This web server's process is: <%= System.Environment.Is64BitProcess ? "x64" : "x86" %>
        <br />
        Operating system information: <%= String.Format("{0}", System.Environment.OSVersion) %>
        <br />
        .NET version: <%= String.Format("{0}.{1}.{2}", System.Environment.Version.Major, System.Environment.Version.Minor, System.Environment.Version.Build) %>
    </h2>
</body>
</html>


Re: Could not load file or assembly 'PDFNet.dll' ' when using PDFNet for .NET 4.x Mirko 3/21/13 2:33 AM
Hi Vincent,
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: