Could Not Load File or Assembly - Incorrect Format - Partial Binding

1.1k views Asked by At

I am trying to run an existing solution on my local machine but every time I try to run it I get the error below [image below].

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

I am unsure if it is relevant but it also gives information about partial binding

WRN: Partial binding information was supplied for an assembly

I can't find where the dll "HtmlToPdfBuilder" came from so I can't check if there is a different version. I have got my project set to compile against "Any CPU", but have tried setting it to x64 and x86 and I have also tried setting "Enable 32-bit Applications" to both true and False in IIS.

The dll was sitting in a folder outside the project and referenced, I have tried moving it into the project and referencing it (just incase).

The exact same project works on someone else's machine and we have tried comparing but can't see any differences in set up.

I am running Visual Studio 2012 and this is a VB.NET project.

enter image description here

Update

This is also running on a server

  • I have tried matching my IIS and Website settings
  • I have tried copying all the dlls from the server down to my local machine but still get the same error
  • I have also copied all my local dlls up to the server and the site still runs fine there
  • I have also matched the webconfigs and the only difference is that on the server entity framework is set as Version=4.3.1.0 and locally it is Version=6.0.0.0
2

There are 2 answers

0
Bex On BEST ANSWER

Here's what I finally did to fix this:

  • Re-registered .net and IIS at the command prompt

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis.exe -i

  • Created a new application pool (as messed with so many settings)
  • Set enable 32-bit on the application pool
  • Restarted IIS

I cannot explain why this works, as not got any problems with any other sites, but as it did I thought I'd share incase it helps anyone else.

3
Slukad On

It seems like you are trying to use a 32bit dll on a 64bit application (or viceversa) so here is what you should use.

  1. Open the Visual Studio Command Prompt and type "corflags [pathTo]/[your assembly]", this will tell you the architecture so you can change/verify you have the proper dll.
  2. On Visual Studio go to the reference properties and check where is it being retrieved. Then change the refresh path to your dll path accordingly and also set the copy local to true.
  3. Rebuild and run.
  4. If it is also running on IIS, set Enable 32-bit Applications to true.