3

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

This is for a test console app I'm making to read barcodes... VS2010 C#.

Also, I most definitely have access to the file, it's a reference to a network file but have tried referencing it locally, checked permissions, etc etc

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
tnw
  • 13,521
  • 15
  • 70
  • 111

7 Answers7

6

The message typically means that you are trying to load a 32 bit DLL on a 64 bit system or vice versa.

Verify that you have the correct version of the DLLs and their dependencies.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
3

To tnw:

This is Daoud from LEAD support. About the different builds of our imaging .NET DLLs, there are 4 distinct copies of each DLL (not including the Silverlight or WinRT builds), which are:

  • 32-bit .NET 4
  • 64-bit .NET 4
  • 32-bit .NET 2 to 3.5
  • 64-bit .NET 2 to 3.5

This means the suggestions posted here by the different users are mostly correct. You should use the correct DLL build for your platform and framework version. But if you still face any problems with our toolkit, send us an email to support@leadtools.com and we will work with you on isolating the problem. We usually respond within the same business day and no later than the next day.

Also make sure the correct DLLs are being loaded at runtime, since if your PATH or GAC contain multiple copies of the DLL, the wrong build can get loaded.

A final note about Ivan Leonenko's response: The information presented are correct for our Multimedia toolkit filters and codecs users. However, tnw appears to be using our imaging .NET assemblies, which are different .NET DLLs and do not have "wrappers".

LEADTOOLS Support
  • 2,755
  • 1
  • 12
  • 12
3

Set Enable 32 bit Application in Your Application Pool as true in IIS and then try . I think it will work Because this is platform related issue.

2

A BadImageFormatException is caused by a platform mismatch. You are either targeting x86 in your project when the Leadtools assembly was compiled for x64 or vice versa.

To fix this look at the properties of your project in Visual Studio. The platform is on the build tab and will be something like x86, x64 or AnyCPU.

You may have to use configuration manager (found under the build menu) to add another platform.

Here is a Microsoft support article with more info

Mark Arnott
  • 1,975
  • 3
  • 17
  • 28
  • Excellent, changed it over to x64 and I am no longer getting this exception (kinda). Now its causing an exception on `LeadHelper.Unlock()`: `Could not load file or assembly "microsoft.licensing.runtime2.0"` – tnw Sep 04 '12 at 14:25
  • I can't find 'microsoft.licensing.runtime2.0' on my development machine. So I suspect that it is an add on to the .Net framework. I am guessing that you will need to reference the 64 bit version of that dll to resolve this new exception – Mark Arnott Sep 04 '12 at 16:49
0

It looks like you are targeting the wrong framework for that dll. Try switching the framework of the csproj that is referencing the dll.

I'm not sure what framework leadtools was built in, but try building in every other framework (4.0 client, 4.0, 2.0, etc...).

More Information: http://msdn.microsoft.com/en-us/library/bb398202.aspx

Localghost
  • 714
  • 3
  • 7
0

You're trying to reference wrong assemblies. You should try wrappers for your case from dist folder of LEAD SDK for 4.0 or 2.0 .NET Framework.

I was using their screen capture and codecs, and I referenced only needed files (.NET wrappers): LEncH2644.dll LMISOMux.dll LMScrCap2.dll LMVRGBxf.dll

But you should deliver separately LEAD's core files: Leadtools.Multimedia.dll, ltmm.manifest, ltmm175.dll, DSKernel2.dll. Last two must be registered on the system(regsvr32).

Leadtools.Multimedia.dll must be referenced in project that locks/unlocks components.

Ivan Leonenko
  • 2,363
  • 2
  • 27
  • 37
0

I have installed Microsoft Visual C++ 2008 & 2010 SP1 Redistributable Package (x86).

Then, enabled 32 bit Application in the Application Pool as True in IIS. It worked perfectly.

Jey
  • 1
  • 2