IBM Support

System.BadImageFormatException: Could not load file 'IBM.Data.DB2.dll'

Troubleshooting


Problem

.NET application using IBM DB2 .NET Provider (IBM.Data.DB2.dll) fails with: System.BadImageFormatException: Could not load file or assembly 'IBM.Data.DB2' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Symptom

Error message:
Could not load file or assembly 'IBM.Data.DB2' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'IBM.Data.DB2' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Cause

Local copy of the IBM.Data.DB2.dll in the application's local directory.

Resolving The Problem

IBM.Data.DB2.dll has dependencies on other client libraries in DB2 Client installation. So refer the DLL from the DB2 Client installation location only and do not save a local copy in the application directory.

In MicroSoft Visual Studio, there is an option to keep a local copy of the assembly:
http://msdn.microsoft.com/en-us/library/t1zz5y8c%28v=vs.90%29.aspx

If you have the "Copy local" value set to true, a local copy of the DLL gets created in the application directory. Changing "Copy Local=false" will avoid creating a local copy of the DB2 provider in the application directory.

Related Information

[{"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"Programming Interface - .NET\/.NET ADO","Platform":[{"code":"PF033","label":"Windows"}],"Version":"9.7;10.1;10.5","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
16 June 2018

UID

swg21902663