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

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"
  • 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 res (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 Web Application

You get a System.BadImageFormatException (an attempt was made to load a program with an incorrect format) after you have deployed your ASP. NET project to your IIS web server. During development there was no such problem.

Reason: Visual Studio is a 32 Bit application and the development server usually runs as 32 Bit process. Therefore the 32 Bit version of TECIT.TBarCode.DLL has been embedded into your project and is now part of your ./bin folder. But your IIS runs the worker thread as 64 Bit process and now loads the wrong format.

Option #1: Deploy the 64-Bit version of the Assembly

Use the version from the C:\Program Files\Common Files\TEC-IT\TBarCode\[version] folder (this is the x64 version). Exchange the ../bin/TECIT.TBarCode.dll file on your target system with that version.

Option #2: Let the GAC do the work

Remove the TECIT.TBarCode.dll completely from your bin folder. In that case the TECIT.TBarCode.dll from the global assembly cache (GAC) will be loaded. The common language runtime loads the correct version automatically because the GAC holds both versions, 32 and 64 Bit. Prerequisite: The setup of TBarCode SDK must be executed on the target server, the setup installs the DLLs in the GAC for you.

If you don't see an effect immediately, restart your application pool or perform an "iisreset" on the command line (take care, this restarts ALL and sessions will be lost).

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.ContentType = "image/gif";

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


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.