BadimageFormatExeption

This is where you talk about Plugins. How they are made and how they work, show examples.

BadimageFormatExeption

Postby Dan911 » Sun Jul 15, 2018 12:15 pm

Hi Everyone,
I use a plugin I"ve written to use with my joystick with all axis, buttons configured the way I like. Worked great up to UCCNC 1.2047. I just tried loading in 1.2105 and I'm getting the "BadimageFormatException", the cause is from the Microsoft.DirectInput dll. After some reading and research the only solution I found was to compile with x86 which is no solution since AnyCPU is needed to work in uccnc 1.205.

The plugin was compiled in .Net2/AnyCpu, I was hoping there maybe some simple solution before taking the plunge and have to learn SlimDX or SharpDX for the directInput.

Any help appreciated!

Thanks,
Dan
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: BadimageFormatExeption

Postby cncdrive » Sun Jul 15, 2018 1:26 pm

Hi Dan,

BadimageFormatException exception happens when a 32bits application tries to load a 64bits assembly or a 64bits application tries to load a 32bits assembly.
If the mentioned .dll file contains native code (not a .NET .dll) then the only solution for this problem is to have both the 32bits and 64bits version of the same dll and load the appropriate one depending on the platform the UCCNC is running on (32bits or 64bits Windows.)

The version 1.2047 was still compiled with x86, so it always runs as a 32bits process even on 64bits Windows and so that UCCNC version can always load 32bits dll files, but it can't load 64bits ones.
The newest UCCNC versions were compiled with AnyCPU and so they running as a 32bits process on 32bits Windows and as a 64bits process on 64bits Windows and so you will have to load the proper image format assemblies depending on what platform the software is running on.

We doing the same with the UC100.dll which is the motion control API of the UCCNC software and is a native code not .NET, so we have to have both 32bits and 64bits versions.
What we do is when the UCCNC startsup it checks if the platform is 32bits or 64bits and also checks if the UC100.dll version in the UCCNC folder is the 32bits or the 64bits version and if nessessary then it copies the proper .dll file into the folder before the software is calling any dllimport.
This way the software is easily portable between computers even with copying all files and folders without an installation, because the UCCNC always checks the .dll on startup and replaces with the proper one when nessessary.
cncdrive
Site Admin
 
Posts: 4695
Joined: Tue Aug 12, 2014 11:17 pm

Re: BadimageFormatExeption

Postby Dan911 » Mon Jul 16, 2018 1:38 pm

Hi Balazs,
Thanks for the explanation....Yes, the problem only happens with UCCNC 2105 loaded on a 64bit system. What was confusing me is if I create a exe file with plugin it ran on 64bit system outside UCCNC but than realized I compiled x86 target. Thanks again, a lot more reading/learning.

Dan
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA


Return to Plugins

Who is online

Users browsing this forum: No registered users and 6 guests