Dotnet apps not porting to KMotion 5.3.1 libs

Moderators: TomKerekes, dynomotion

Post Reply
SamMarrocco
Posts: 85
Joined: Fri Apr 27, 2018 12:44 pm

Dotnet apps not porting to KMotion 5.3.1 libs

Post by SamMarrocco » Thu Dec 07, 2023 4:53 pm

I've attempted an upgrade of my dotnet application from KMotion 4.34 libraries to 5.3.1, but am experiencing some issues.
The current version of my app runs normally with KMotion 4.34 libraries and firmware.

Issue #1: The KMotion.exe that is packaged with 5.3.1 cannot update the firmware on my KFlop to the 5.3.1 firmware. After "Yes"-ing the usual "Error Status Record Size mismatch" dialogs during the firmware update process and selecting the New Version/5.3.1 firmware file, downloading begins. After a few seconds, two dialogs appear (KMotion No Response) and (Unable to connect to KMotion Server). I can only update the firmware of the 4.34 KFlop if I use the 4.34 KMotion with the 5.3.1 Firmware file. If I do this, the firmware downloads successfully.

Issue #2: Armed with the 5.3.1 updated KFlop, I then update my dotnet apps as usualy. This process involves copying the following KMotion files from the KMotion Debug|Release folder:
KMotionDLL.dll
KMotion_dotNet.dll
KMotion_dotNet_Interop.dll
GCodeInterpreter.dll
KMotionServer.exe
TCC67.exe
emc.var
...into the debug|release folder of my dotnet applicaton.
I then Copy the folder DSP_KFLOP and it's contents from C:\KMotion<Version> into my Debug1|Release1 folders.

This process has worked through KMotion 4.34. But with 5.3.1, my code compiles under Visual Studio.Net 2022 using the dotnet framework 4.8 but fails to run, presenting an error during initialization of a KM_Controller with this statement:


CODE LINE 12: Public WithEvents ThisController As New KM_Controller

KMotion_dotNet.DMException
HResult=0x80131500
Message=Dll Not Found Exception thrown : Caller - [KMotion_dotNet.KM_Controller] :: Member - [KM_Controller]
Source=KMotion_dotNet
StackTrace:
at KMotion_dotNet.KM_Controller..ctor(Boolean DoNotObtainConsoleMessages)
at MillDroid.MainForm_Class..ctor() in Z:\CodeArchive\VB.Net_2023\MillDroid\MillDroid_7.0.2479\Form Classes\MainForm_Class.vb:line 12

The KMotion_dotNet dll is definitely present and updated to the KMotion 5.3.1 version, and is referenced in the project as it always has been. KMotion_dotNet_Interop.dll is also present in the app's executable folder.

This is a new Windows 11 Pro machine, with the Memory Protection disabled to allow the drivers to work, and a fresh install of Visual Studio 2022. I am assuming that previous versions of Visual Studio 2019 are no longer required, nor are their older debug libraries with the new KMotion dotnet libraries.
Because I use the debug versions, I also have installed the "Microsoft Visual C++ 2015-2022 Redistributable (x86) - 14.38.33130" for debugging.

I've reviewed the release notes since 4.34 but can't find anything that seems like it would be a change that could cause this.

Do you have any suggestions for how to proceed?

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: Dotnet apps not porting to KMotion 5.3.1 libs

Post by TomKerekes » Thu Dec 07, 2023 7:25 pm

Hi Sam,

Regarding #1 - Thanks for the feedback. We are working to resolve this. You should also be able to use the recovery option to get around this.

Regarding #2 - It's saying it can't load KMotion_dotNet.dll or one of its dependencies.

Those files seem to work ok for me testing 5.3.1 with the SimpleFormsCS C# .NET example. I have a folder with these files:

MinFiles.png

You might copy SimpleFormCS.exe to your Debug folder to see if it runs.

Another dependency is ftd2xx.dll but that is normally somewhere in the Windows path after the USB Driver is installed. But you might copy it in to be sure. Or verify it by running SimpleForrmsCS.

Is your App being built and run as a 32-bit (x86) App? If you are selecting AnyCPU it would normally run as a 64-bit App when on a 64-bit environment.
Regards,

Tom Kerekes
Dynomotion, Inc.

SamMarrocco
Posts: 85
Joined: Fri Apr 27, 2018 12:44 pm

Re: Dotnet apps not porting to KMotion 5.3.1 libs

Post by SamMarrocco » Fri Dec 08, 2023 1:01 am

Tom,
Regarding the possible "missing KMotion_dotNet.dll or one of its dependencies".

Per your suggestions, I checked, and ftd2xx.dll does exist in my system path (in C:\Windows\System32, and a few other locations) and also in the debug folder of my previous working versions for 4.3. I seem to recall that also being a 'safety' to perform during some earlier driver troubleshooting years ago. So, I copied the ftd2xx.dll from my c:\KMotion5.3.1\USB Driver\i386 folder into my app's debug folder. This did *not* resolve the issue.

I then copied SimpleFormsCS.exe from c:\KMotion5.3.1\KMotion\Debug into my app's debug folder and ran it. It tried to run, but nothing ever appears on screen. I then attempted to run it from its home of c:\KMotion5.3.1\KMotion\Debug. Same result-it tries to start but nothing visible ever appears. This is a fresh KMotion 5.3 install to which I haven't changed anything.

I then went into C:\ProgramData\Microsoft\Windows\WER\ReportArchive and checked for a crash log and found a folder named:
AppCrash_SimpleFormsCS.ex_25b1f215ca6295cc21822dcfacab35161f247f_59eacd5f_1a1700fd-8fdc-40c9-8eda-9da168f0ca22 with a Windows Error Report file. I've attached that file to this post.

In answer to your questions: Yes, my app's target CPU is x86, but if SimpleFormsCS is not running from the default location in KMotion, it seems as though the issue must be external to my app.

As a sanity check, I ran KMotion (5.3), went into the Console section and performed some of the example console commands: Version is returning 5.3.1, and the rest of the console examples seem to work fine.
Attachments
Report.zip
(3.36 KiB) Downloaded 247 times

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: Dotnet apps not porting to KMotion 5.3.1 libs

Post by TomKerekes » Fri Dec 08, 2023 2:04 am

Hi Sam,

Clicking on C:\KMotion5.3.1\KMotion\Debug\SimpleFormsCS.exe of a Fresh install of 5.3.1 runs for me on both my W10 and W11 systems. That suggests something different about our PCs

Maybe try a different PC?

You might try disabling Windows Defender or any Anti-Virus.

Maybe you don't have .NET 4.8 installed?

I think you can check from the CMD prompt with:

Code: Select all

reg query "HKLM\SOFTWARE\Microsoft\Net Framework Setup\NDP" /s
Regards,

Tom Kerekes
Dynomotion, Inc.

SamMarrocco
Posts: 85
Joined: Fri Apr 27, 2018 12:44 pm

Re: Dotnet apps not porting to KMotion 5.3.1 libs

Post by SamMarrocco » Fri Dec 08, 2023 6:18 pm

This one is becoming quite a bugger to solve....

Per your suggestion, I installed KMotion 5.3 on another machine; this one, a Windows 10 machine that is still able to run KMotion 4.34/My app. The 4.34, and my app using those libs works normally. I recompiled my app using the 5.3 libs, and it works fine on that machine also as does SimpleFormsCS.

Back to my Windows 11 machine, I uninstalled all virus protection (malwarebytes, defender, etc) and I did a remove-reinstall of the KMotion 5.3. I manually removed all KMotion libs from my app's debug folder, and attempted to compile just so I could see it fail and maybe clear out any 'caches' that might still exists. I rebooted, then manually copied the KMotion 5.3 libs to my app's debug folder and re-added them to my VS2022 project. I had the same issue after trying to run my app or SimpleFormsCS on the Windows 11 machine.

So far, the only thing I know is that KMotion 4.3 works fine on this machine, but KMotion 5.3 does not (neither KMotion apps nor mine).

Very odd.....

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: Dotnet apps not porting to KMotion 5.3.1 libs

Post by TomKerekes » Fri Dec 08, 2023 7:36 pm

Hi Sam,

I'm assuming when you say 4.3 you mean 4.34 and when you say 5.3 you mean 5.3.1?

I'd focus on getting SimpleFormsCS to work before doing anything with your App.

Maybe you don't have .NET 4.8 installed? I think 4.34 targeted .NET 4.5

I assume C:\KMotion5.3.1\KMotion\Debug\KMotion.exe runs fine?
Regards,

Tom Kerekes
Dynomotion, Inc.

SamMarrocco
Posts: 85
Joined: Fri Apr 27, 2018 12:44 pm

Re: Dotnet apps not porting to KMotion 5.3.1 libs

Post by SamMarrocco » Sat Dec 09, 2023 2:34 am

Tom,
Yes, sorry. All my tests have been between KMotion libs and firmware 4.3.4 and 5.3.1.
Yes, KMotion 5.3.1 runs and returns version numbers and other console tests.
The dotnetframework 4.8 is installed, as that command line (you suggested) does show 4.8.09032
All anti-virus (defender, malwarebytes) is disabled and rebooted with them off.

It's very strange about the error of not finding KMotion_dotNet.dll when it's right there, and VS's intellisense can read the methods and properties within, and the solution/project can see that they are there. The fact that whatever this is is also affecting SimpleFormsCS means it has to be external to the VS UI or my code, and related to the KMotion install itself, so I'll try to focus on why that isn't running. SimpleForms behaves exactly like my app when compiled (doesn't even get to a Forms UI display, just fails to visually start.

SamMarrocco
Posts: 85
Joined: Fri Apr 27, 2018 12:44 pm

Re: Dotnet apps not porting to KMotion 5.3.1 libs

Post by SamMarrocco » Sun Dec 10, 2023 3:10 pm

Tom,

I was assuming that, because the current version of KMotion libs is 'VS2022 compatible', that it installs everything it needs to run all its apps. Since my new machine was a "Windows 11, VS2022, and nothing else (no legacy VS2019 or earlier versions as I had in other locations) it seemed like a good time to minimize my developer libs with a fresh machine.

I don't usually use KMotionCNC, but while testing I noticed that KMotionCNC Debug Version doesn't run on this new W11, dialoging "The code execution cannot proceed because mfc140d.dll was not found. Reinstalling the program may fix this problem." My code is running as Debug versions as well, although it doesn't show that error message, which I'm guessing you are trapping in your KMotionCNC source code. SimpleFormsCS debug did NOT present this error dialog when failing to run, probably for that reason.

If I'm not mistaken, this is similar to something we discusses a few years ago, when a vs2019 required something that vs2015 or earlier had installed by defaults (Debugging libraries for MFC I think). Perhaps because the Debug versions of MFC cannot be redistributed with your app?

All said, if this is a case of not being able to run debug versions of the KMotion apps/libs because the debug version of an MFC library is missing, I'm guessing that I need to perform an additional install of a module from within the VS installer (although I'd prefer to just install something without doing it in VS so I can perform it on test machines that do not have VS installed). I'm going to try installing C++ MFC from within VS's installer........

......and that was the problem! All the debug versions of KMotion apps now work, as does my app. Once again, an issue related to debug MFC libs.

I am curious though, why the debug version of KMotion present the missing mfc140d.dll error, but the debug SimpleFormsCS did not? Is it because you are trapping the error in KMotionCNC but not in SimpleFormsCS?

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: Dotnet apps not porting to KMotion 5.3.1 libs

Post by TomKerekes » Mon Dec 11, 2023 1:09 am

Hi Sam,

Glad you figured it out.

I don't know why Microsoft makes it so difficult to report which dll is not found.

I'm not sure but the difference might be that with SimpleFormsCS the missing dll is further down the chain

SimplFormsCS.exe -> KMotion_dotNet.dll -> KMotion_dotNet_Interop.dll -> mfc140d.dll
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply