Error referencing KMotion_dotnet dll on .NET 6.0 project

Moderators: TomKerekes, dynomotion

gui_marchioro
Posts: 59
Joined: Sun Aug 21, 2022 11:22 pm

Error referencing KMotion_dotnet dll on .NET 6.0 project

Post by gui_marchioro » Wed Jan 10, 2024 11:50 pm

Hello,

I am getting an error when trying to reference the KMotion_dotnet on a .NET 6.0 project. It states that it is not possible to load file or assembly.
kmotion_dotnet_error.png
Is there a workaround that I can do in this situation?

Here you can see the reference to the dll:
kmotion_dotnet_error2.png
Sincerely,
Guilherme

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

Re: Error referencing KMotion_dotnet dll on .NET 6.0 project

Post by TomKerekes » Thu Jan 11, 2024 3:10 am

Hi Guilherme,

Please read this Thread.
Regards,

Tom Kerekes
Dynomotion, Inc.

gui_marchioro
Posts: 59
Joined: Sun Aug 21, 2022 11:22 pm

Re: Error referencing KMotion_dotnet dll on .NET 6.0 project

Post by gui_marchioro » Thu Jan 11, 2024 8:12 pm

Hello,

Thanks for the reply.
I upgraded the library to the same version as my app but still the same error occurs, so perhaps this was not the problem.

Sincerely,
Guilherme

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

Re: Error referencing KMotion_dotnet dll on .NET 6.0 project

Post by TomKerekes » Thu Jan 11, 2024 8:29 pm

Hi Guilherme,

Did you rebuild the Debug | x86 Configuration libraries?

You might try building/running the SimpleFormsCS example to see if it works.
Regards,

Tom Kerekes
Dynomotion, Inc.

gui_marchioro
Posts: 59
Joined: Sun Aug 21, 2022 11:22 pm

Re: Error referencing KMotion_dotnet dll on .NET 6.0 project

Post by gui_marchioro » Thu Jan 11, 2024 9:24 pm

Hello

Do you mean the ones from BuildAllLibs.sln? If so, yes I did.

I tested upgrading SimpleForms and it worked. However, the same is not true for SimpleGCodeWPF, which is issuing the same error as my app does.

Sincerely,
Guilherme

gui_marchioro
Posts: 59
Joined: Sun Aug 21, 2022 11:22 pm

Re: Error referencing KMotion_dotnet dll on .NET 6.0 project

Post by gui_marchioro » Sat Jan 13, 2024 5:06 pm

Hello,

Well I think I'll be forced to use the old .NET framework in my project, since I can't solve the problem and don't want to spend more time on it.

Maybe if someone reading this is able to use newer versions please comment here how it can be done.

Sincerely,
Guilherme

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

Re: Error referencing KMotion_dotnet dll on .NET 6.0 project

Post by TomKerekes » Sun Jan 14, 2024 8:12 pm

Hi Guilherme,

I tested SimpleGCodeWPF without any problem.

I think your App might be building as AnyCPU rather than what is consistent with the KMotion_dotNet Library.

Here is what I did:

Fresh Install 5.3.1
Open BuildAllLibs.sln
Upgrade KMotion_dotNet to .NET 7
Select Configuration to Debug | x86
ReBuild
Open BuildExamples.sln
Upgrade SimpleGCodeWPF to .NET 7
Note VS22 seems to have a bug that doesn't allow Configuration Manager to select x86 platform to be selected
Removing and re-Adding the SimpleGCodeWPF project to the Solution fixes something
Set Configuration Manager Debug | x86 to build SimpleGCodeWPF as Debug | x86
Select Configuration to Debug | x86
ReBuild SimpleGCodeWPF

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

gui_marchioro
Posts: 59
Joined: Sun Aug 21, 2022 11:22 pm

Re: Error referencing KMotion_dotnet dll on .NET 6.0 project

Post by gui_marchioro » Thu Jan 18, 2024 6:36 pm

Hello Tom, thanks for the reply.

Yes, as you said both KMotion_dotNet and SimpleGCodeWPF were targeting AnyCPU configuration.
I've made the changes you listed step by step, but still I get the same error.

Is there anything else I could try?

Sincerely,
Guilherme

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

Re: Error referencing KMotion_dotnet dll on .NET 6.0 project

Post by TomKerekes » Mon Jan 22, 2024 11:20 pm

Hi Guilherme,

I tried Upgrading to .NET 7 on another computer (HP Laptop W11 64-bit) and had a few issues but eventually got it to work.

You are using Upgrade Assistant correct? This needs to be installed.

My VS22 was somewhat old 17.4 and upgraded assistant wouldn't work correctly. I updated VS22 to the current latest 17.8.5

I had to install .NET 7 SDK. Even though I only planned to use 32-bit (x86) I found I had to install 32-bit and 64-bit .NET 7 SDKs to get Upgrade to work. I installed Version 7.0.312 for both. Also I installed the 7.0.405 Security Patch.

I noticed code was being placed in C:\KMotion5.3.1\KMotion\Debug\net7.0-windows instead of C:\KMotion5.3.1\KMotion\Debug. Running from VS gave the KMotion_dotNet.dll error. But looking at the inner exception details it shows a root problem loading KMotion_dotNet_Interop.dll I think VS is running from thenet7.0-windows folder which doesn't contain KMotion_dotNet_Interop.dll

I found 2 solutions:

#1 - tell VS to set the working directory to C:\KMotion5.3.1\KMotion\Debug so it finds all the necessary dlls.

WorkingDirectory.png

#2 - is probably the better solution is to place the output properly in C:\KMotion5.3.1\KMotion\Debug. There doesn't seem to be any way to stop from appending the Target Framework folder for the output except by manually editing the C# project file. Within the PropertyGroup set the AppendTargetFrameworkToOutputPath to false.

AppendFalse.png

Note there seems to be an issue/bug in VS2022 where right click project | Edit Project File sometimes doesn't appear in the context menu unless the project is unloaded first.
Regards,

Tom Kerekes
Dynomotion, Inc.

gui_marchioro
Posts: 59
Joined: Sun Aug 21, 2022 11:22 pm

Re: Error referencing KMotion_dotnet dll on .NET 6.0 project

Post by gui_marchioro » Thu Feb 01, 2024 3:38 am

Hi Tom,

I am currently using VS 2022 (64-bit) V 17.8.6, which indeed has the Upgrade Assistant.
I installed the SDKs that you mentioned and retried the process, but still the error persisted. I also noticed that the code was being placed inside the folder you pointed, and tried the workarounds proposed, which were not successful. :cry:
I don't know what else I could be missing in the upgrade.

Did you get the same error when trying to upgrade?
error_SimpleGCodeWPF.png
Sincerely,
Guilherme

Post Reply