FAQ TBarCode .NET
Bad Image Format Exception After Deployment of a Desktop Application
Bad Image Format Exception After Deployment of a Desktop Application
The following applies to TBarCode .NET versions before 11.15.
You get the following exception after you have deployed your Windows Desktop application.
System.BadImageFormatException: Could not load file or assembly 'TECIT.TBarCode, Version=11.10.0.0, Culture=neutral, PublicKeyToken=1b5f4306b234b83d' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Reason for the problem: During development you referenced the 32 bit version of the DLL. Now at deployment, the EXE is executed as 64 bit process and cannot load the TECIT.TBarCode.dll (which is 32 bit).
Background information:
Because of loading native libraries, the TECIT.TBarCode.dll is platform specific and not marked as CPU=Any. On the development computer you usually execute the program as 32 bit process, because Visual Studio is a 32 bit application. But also if the process runs as 64 bit (either with CPU=Any or CPU=x64) it still can load the required DLLs from the GAC and from the program files/common files folder. Our setup installs both versions (32 bit + 64 bit) and extends also the search path. So it will always find the DLLs.
Then when moving to the target system, because of managed code, the executable can run either as 32 bit or 64 bit. In some cases the process cannot find the correct DLLs because it switches from 32 to 64 bit automatically, or the DLLs are not in the search path or GAC or just not installed.
Proceed as follows – chose one of the options below:
Build your EXE with target CPU x86
Reference the TECIT.TBarcode.dll in the “C:\Program Files (x86)\Common Files\TEC-IT\TBarCode\11*” folder and copy the TECIT.TBarcode.dll + TBarCode11.dll + zlib1.dll to your deployment folder. The zlib1.dll is only needed if you use gzip compression with 2D codes. Install the x86 VCRedist from Microsoft (2015 U3 RC or the newer 2015-2019 edition).
Build your EXE with target CPU x64 (64 bit)
Reference the TECIT.TBarcode.dll in the “C:\Program Files\Common Files\TEC-IT\TBarCode\11*” folder and copy the TECIT.TBarcode.dll + TBarCode11_x64.dll + zlib1.dll to your deployment folder. The zlib1.dll is only needed if you use gzip compression with 2D codes. Install the x64 VCRedist from Microsoft (2015 U3 RC or the newer 2017–2026 edition).
Build your EXE with target CPU Any
For programming, reference the TECIT.TBarcode.dll in the “C:\Program Files (x86)\Common Files\TEC-IT\TBarCode\11*” folder. For deployment don’t copy any TEC-IT DLLs along with your EXE. Remove the TECIT.TBarCode.dll from your deployment folder. Instead install the TBarCode SDK Setup and select only the TBarCode .NET component from the features list – this will install x86 and x64 versions parallel into the GAC and extends the PATH variable with the DLL path. The TBarCode Assembly will be loaded automatically in the correct version because it is in the GAC for 32 and 64 bit. If you don’t want to execute the TBarCode Setup manually, it can be also automated by applying command line switches (silent setup). Install both the x86 and x64 VCRedist from Microsoft (2017–2026 edition).