2

I have a .Net 4.5 WPF MVVM application I have added scanning support using the TWAINDotNet. All of the scanning features work fine until I build in Release and deploy. I confirmed that everything is getting built using the same .Net and "Any CPU" for the processor.

2020-04-03 16:06:33,169 [1] ERROR ScanningViewModel ScanningViewModel (null)
- ScanFromDevice An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) - at TwainDotNet.TwainNative.Twain32Native.DsmParent(Identity origin, IntPtr zeroPtr, DataGroup dg, DataArgumentType dat, Message msg, IntPtr& windowHandle) at TwainDotNet.DataSourceManager..ctor(Identity applicationId, IWindowsMessageHook messageHook) at TwainDotNet.Twain..ctor(IWindowsMessageHook messageHook) at TestMain.Scanning.ViewModels.ScanDocumentViewModel.get_objTwain() at TestMain.Scanning.ViewModels.ScanDocumentViewModel.ScanDocumentFromDevice() System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at TwainDotNet.TwainNative.Twain32Native.DsmParent(Identity origin, IntPtr zeroPtr, DataGroup dg, DataArgumentType dat, Message msg, IntPtr& windowHandle) at TwainDotNet.DataSourceManager..ctor(Identity applicationId, IWindowsMessageHook messageHook) at TwainDotNet.Twain..ctor(IWindowsMessageHook messageHook) at TestMain.Scanning.ViewModels.ScanDocumentViewModel.get_objTwain() at TestMain.Scanning.ViewModels.ScanDocumentViewModel.ScanDocumentFromDevice()

Chuck
  • 41
  • 1
  • 5
  • 1
    It looks like your release build has a different bitness to your debug build - you have a 64-bit program loading a 32-bit dll, or vice-versa. – Simon MᶜKenzie Apr 03 '20 at 22:16
  • Does this answer your question? [Could not load file or assembly ... An attempt was made to load a program with an incorrect format (System.BadImageFormatException)](https://stackoverflow.com/questions/11370344/could-not-load-file-or-assembly-an-attempt-was-made-to-load-a-program-with-a) – Simon MᶜKenzie Apr 03 '20 at 22:18
  • Highlights from the link include confirming that the actual Target CPU for your project's Platform actually match - the Platform name is just a string, so an x64 or AnyCPU Platform can still target x86. And it's deeper in the comments of an answer in the link from Simon, but you might also check the 'Prefer 32-bit' flag if your Target CPU is set for AnyCPU. – Sean Skelly Apr 03 '20 at 22:51
  • Thank you for all of the feedback. So if the target CPU is set to Any CPU where in the Visual Studio 2017 configuration would it be using x64? – Chuck Apr 04 '20 at 12:38

0 Answers0