Unable to Load the DLL: 'TBarCode11_x64.dll'

You may receive this kind of error when you call an ASP.NET web page, which contains a TBarCode .NET Web Control or a Barcode Class from the TBarCode .NET Assembly.

The possible reason for this problem is that either the DLLs have not been installed or are not available for the IIS process. It can also be that the 32 Bit version has been installed but the IIS application pool is set to 64 Bit.

The solution would be to install our TBarCode x64 MSI setup and initiate a restart of the IIS service in order to make the IIS process read in the updated PATH variable.

Start an admin console (run as Administrator) and enter

iisreset
This will restart all IIS processes and afterwards the DLL should be found. The MSI setup installs the .NET component into the GAC and puts all dependencies (folders) into the PATH environment variable.

If your web server hosts also other applications you should do the reset in a dedicated maintenance time frame or while nobody else accesses the server.

Incorrect Format Error

After deploying your web application you get:

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

The possible reason for this problem is that you added the 32-bit variant of the TBarCode Assembly to your application (typically because Visual Studio development web server runs in 32 bit mode). But your web server is running on a 64 bit system and your application pool is adjusted to not support 32 bit. Now the application wants to load a 64-bit library but it finds the 32 bit version instead, this leads to the incorrect format error.

There are two options for a solution:

  1. You can switch to 32 bit by changing the Enable 32 Bit property in your IIS application pool (advanced settings). I suggest to do that only if your web application has a dedicated application pool configured only for this one app and there is no requirement to run the app as 64 bit.
  2. Or you remove all TBarCode relevant libraries from your app/bin folder, install the TBarCode x64 SDK MSI setup on your web server and then do either a reboot or run the iisreset command on an admin console prompt (all apps are restarted). Doing it that way IIS will resolve either the 64 bit or the 32 bit variant from the GAC (Global Assembly Cache) automatically. In the GAC our setup stores copies of the TBarCode Library/Assembly in both 32 and 64 bit formats.
If your web server hosts also other applications you should do a reset in a dedicated maintenance time frame or while nobody else accesses the server.

Delays on the Web Server

When running TBarCode on IIS for Windows behind a firewall, a possible delay of 15-30 seconds may occur when the first page is hit. This is caused by IIS because it is authenticating signed .NET / DLL components.

The solution is to replace all TBarCode DLL files with unsigned versions. These are available on request, please contact the TEC-IT support!

Barcode Optimization in Web Applications

When generating bar codes as image stream, the bars (or spaces) should always be aligned on the pixel grid of the generated bitmap.

Note: Without any scaling images in a browser are always displayed in 96 dpi. A thin bar having 1 pixel is normally 1/96 inch wide.

Principally, you shouldn't have any problems printing 96 dpi image on a laser printer with 600-1200 dpi. There are some printing tolerance which may occur while converting 96 dpi to 600/1200 dpi but they are minimal.

In ASP the CountModules, XRows, XCols functions can be used for adjustments. Look at the ASP and PHP samples delivered within the setup. For ASP.NET refer to the sample code below.

It might eventually be more complex to adjust the barcode to a specific size or to adjust the printing resolution to 300 dpi or lower. In this case, you should adjust the barcode module width to the dot-width of the printer.

See section A.4 in the Barcode Reference for more information. We recommend reading the whole Appendix A starting with page 83.

Improve Barcode Quality for Label Printers in ASP.NET

If you print barcodes from within the browser on thermal label printers, you often encounter quality problems. The bars are not equal in width and not adapted to output resolution. In order to avoid bar width aberrations you have to find a full match of Pixels across 96 dpi browser and 203 dpi printer resolution. For linear bar codes the solution is as follows:

  • Bitmap creation: Create the bar code bitmap with 203 dpi and optimized module width (2 or 3 Pixels). Make the whole bitmap exactly 3 or 4 inches wide (= 3 * 203 Pixels or 4 * 203 Pixels) by adding white space as required.
  • Bitmap scaling: Display the bar code image in the browser with a width of exactly 3 or 4 inches (= 3 * 203 Pixels or 4 * 203 Pixels) depending on what you have selected during bitmap creation.
  • This will create a pixel aligned bar code to a 203 dpi raster and good readability.

The following ASP.NET C# code shows how to implement this optimization with TBarCode .NET.

 double dpi = 203; // printer resolution (8 lines/mm)
 int numberOfPixels = 3; // number of pixels for 1 module (= 0.375 mm)
 double moduleWidth = numberOfPixels * 25.4 / dpi; // module width in mm
 
 BCControl.Barcode.Dpi = dpi; // 1 bitmap pixel  = 1 module
 BCControl.Barcode.SizeMode = TECIT.TBarCode.SizeMode.CustomModuleWidth;
 BCControl.Barcode.ModuleWidth = (float) (moduleWidth + 0.001);
 BCControl.Barcode.AdjustModuleWidthToPixelRaster = true;
 
 BCControl.Width = new Unit(96 * 4, UnitType.Pixel); // always a multiple of 96 !!!
When printing the barcode make sure that you have browser scaling disabled (or set to 100%). Also make sure that image dithering or halftone is disabled in the printer driver.

ASP: Library Not Registered

"Server object error 'ASP 0177 : 8002801d' Server.CreateObject Failed (..) - Library not registered"

If you get this error message, you need to change the read permissions of IUSR_MACHINE user account for the type library entry in the registry. Please follow the steps below:

  • Start "regedit" or "RegEdt32.exe"
  • Select HKEY_CLASSES_ROOT
  • TBarCode OCX V8: Search for Type Lib UUID {07EC89D3-07F6-4B94-8A6A-C2347DB5C9EC}.
  • TBarCode OCX V9: Search for Type Lib UUID {E06A2F00-D769-46FE-B2D6-E795C0CEE76E}.
  • TBarCode OCX V10: Search for Type Lib UUID {132760F3-28BE-4E8A-B12B-12810EAA1EA3}.
  • Right click on the registry entry and select "Permissions" from the drop down menu. Alternatively, you can also go to Edit -> Permission.
  • On the next dialog, set read permissions of IUSR_MachineName or Everyone account.

How Can I Generate a Pixel-Optimized PDF417 in VB ASP.NET?

Insert this code into the Page_Load event

  Me.BarcodeControl1.Barcode.BarcodeType = BarcodeType.Pdf417
  Me.BarcodeControl1.Barcode.Data = data

  ' TBarCode V7, V8:
  Dim horizModules As Integer
  Dim verticRows As Integer

  horizModules = Me.BarcodeControl1.Barcode.CalculateXColumnsOf2DBarcode()
  verticRows = Me.BarcodeControl1.Barcode.CalculateNumberOfRows()

  Me.BarcodeControl1.Barcode.SizeMode =  SizeMode.FitToBoundingRectangle
  ' for the dpi use at least 3 times the screen resolution (or >= 300 dpi) 
  Me.BarcodeControl1.Barcode.Dpi = 96 * 3
  Me.BarcodeControl1.Width = New Unit(horizModules)
  ' for the height use a multiplier of 3 - 5  
  Me.BarcodeControl1.Height = New Unit(verticRows * 5)

End Sub
In TBarCode V9 and later you can use the new function BCGetOptimalBitmapSize()

Bad Image Format Exception After Deployment of a Desktop Application

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.

Our DLL is a combination of managed code and native precompiled DLLs, so you have to decide if it should run as 32 bit or 64 bit. This decision must be made at compile time when you build the target platform (x86 or x64). If you want to use target CPU=Any, you have to install all DLLs into the GAC (done by our setup). This makes sure that both versions, x86 (32 bit) and x64 (64 bit) are available in parallel.

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 2015-2019 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 (2015-2019 edition).

How Can I Stream a Barcode Image to the Browser (Client)?

With TBarCode it is possible to stream a barcode image (e.g. based on GET or POST parameters) back to the client.

You can take a look on our online barcode generator, where we do this exactly.

This URL streams a barcode image (Data Matrix with the word "TBarCode" encoded) back to the browser: http://barcode.tec-it.com/barcode.ashx

Please use this code snippet for TBarCode .NET as starting point in ASP.NET:

 // first adjust the barcode properties of the myBarcode object (class Barcode)
 // then calculate the width and height of the code in Pixels (sample available on request)
 // then write the barcode image as stream to the browser as follows
 
 Bitmap image = myBarcode.DrawBitmap(width, height);
 image.SetResolution(dpi, dpi);

 Response.Clear();
 Response.ContentType = "image/gif";

 image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);

 HttpContext.Current.ApplicationInstance.CompleteRequest();
 image.Dispose();

The SDK setup contains the Barcode Generator ASP.NET web application (in the samples folder), which is able to stream images to the browser by utilizing the TBarCode .NET Barcode Generator Assembly. This application can be installed on your own web server as well.