How to Solve “BadImageFormatException”

Applies to: SMS API v. 9.2 in Visual Studio Community 2019 and Windows Server 2019 64-bit

Problem: when SMS API v9.2 sample program in run in debug mode, Visual Studio Community 2019 always give this error :-

Inner Exception 1:

BadImageFormatException: Could not load file or assembly ‘Interop.MobitekSMSAPI9, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies.

This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

Solution: change the “Target Framework” of the project to “.NET Framework 4” with these steps:-

  1. Migrate the project “SMS API v. 9.2” to open in Visual Studio 2019.
  2. Open the project. Go to the project “Properties”. In “Application” tab, change the “Target framework” to “.NET Framework 4”.
  3. You will get below warning after changing the “Target framework”. Just click “Yes”.
  4. Close and reopen the project.
  5. Click “Start” button to start debugging the project. Please allow some times for the project to be built.
  6. After the project has completely built, try to click all menus and buttons to see if the problem occur again.