I get an exception on the last line of the following code (sorry for the format, won't let me post it any other way):

LeadHelper.Unlock();

RasterCodecs codecs = new RasterCodecs();

string imageLocation = @"...path...\Barcodes.tif";

RasterImage srcImage = codecs.Load(imageLocation);

The exception reads: System.BadImageFormatException: Could not load file or assembly 'Leadtools.Codecs, Version=17.5.0.0, Culture=neutral, ..........' or one of its dependencies. An attempt was made to lead a program with an incorrect format.

In an effort to try to get rid of this exception, I referenced every possible Leadtools.Codecs.* DLL, Leadtools.dll... pretty much every single Leadtools dll we could possibly reference.

For my includes, I included Leadtools, Leadtools.Barcode, Leadtools.Codecs, Leadtools.Codecs.Tif, Leadtools.Codecs.Fax, and Leadtools.Forms

Hello,
Are you building your .Net project as "Any CPU" and run it on a 64-bit operating system?

If yes, you should NOT build your application with the "Any CPU" configuration. You must specifically build for either 32-bit (x86 CPU) or 64-bit (x64 CPU) because "Any CPU" will cause problems if you run the program on 64-bit systems and include 32-bit DLLs.
If you don't know how to change this configuration, please do the following:
1- From the Project menu, select [project name] properties.
2- From the build tab, change the "Platform target" from "Any CPU" to "x86 CPU" and include the 32-bit DLLs from our toolkit.
3- Build your project and run it. This should work on both 32-bit Windows and also 64-bit Windows.
4- If you only want to target 64-bit Windows and use our 64-bit DLLs, use the same steps above, but choose "x64 CPU" and include our 64-bit DLLs.

Also, if you are using the .Net FrameWork 4.0, you must add your references from the "Dotnet4" folder. If you are using older versions of the .Net framework, you must add your references from the "Dotnet" folder.

If the problem persists, please answer the following questions:
1. What is the operating system (Windows version) that you use? And is it 32-bit or 64-bit?

2. Try to isolate the problem in a small working project (NOT your full application) and send it to me in a ZIP or RAR file. Also, provide me with the exact steps to reproduce the problem using your project. You can post it here or send it to support@leadtools.com and mention this forum post. If you want to attach a file on the forums, do not use the Preview feature.

In case someone is searching for BadImageFormatException and comes across this post, I recently posted an article on our blog about the BadImageFormatException that explains what to look for when trying to solve this problem.

Even after making changes to the Platform target i am getting the same error. I have taken a 64bit dll and updated as AnyCpu in the platform target but still i can see the same error.

"BadImageFormatException: Could not load file or assembly 'Leadtools.Codecs, Version=20.0.4.0, Culture=neutral, PublicKeyToken=9cf889f53ea9b907' or one of its dependencies. An attempt was made to load a program with an incorrect format."

The instructions listed above does a great job of describing the debugging steps. To briefly summarize what causes the "BadImageFormatException", it's often one of two things.

1: The architecture of your application, either x86 or x64 bit, does not match the architecture of your DLLs. This means that if your application is using the 64 bit architecture, but you are using 32 bit (x86) DLLs, you will have this issue.

2: The architecture of your application, either x86 or x64 bit, is using a DLL that does not match the rest of your application. You will need to ensure that all your DLLs match the architecture of your program.

I have attached a zip file which contains screenshots of this debugging process conducted in Visual Studio 2017. Please be sure to check all the LEADTOOLS references to ensure that all the DLLs support the intended architecture. If you are still having this issue after reviewing the discussions of this post, please email us at support@leadtools.com.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.