Issue after updating Peak.PCANBasic.NET to version 4.10.0.964

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
LudovicC
Posts: 9
Joined: Thu 19. Sep 2024, 16:44

Issue after updating Peak.PCANBasic.NET to version 4.10.0.964

Post by LudovicC » Fri 20. Dec 2024, 10:04

Hello everyone,

I am using .NET framwework 4.8 to make a C# class library using the Peak Basic API.
I was until yesterday running the version 4.9.0.942 without issue.
Then I have noticed in the Nugget package that 4.10.0.964 was available with a new parameter PCAN_DEVICE_GUID, which sound very interesting, hence I have decided to update to the latest version. Quite a bad idea to try that right before Christmas vacation ! :D
After the update, my code is not working anymore. I am not originally a C# programmer, so maybe I have missed something very basic.

I have two projects in my solution a "Class Library (.NET Framework)" which is my main code, and a "Console App (.NET Framework)" which is for testing my class library.
I have also downloaded from Peak website the latest PCAN-Basic with "Download Latest Version".

Therefore, for the update I have:
  • Updated the Peak Nuget package to 4.10.0.964 for both projects
  • Copied in each project's folder the file "\PCAN-Basic\Include\PCANBasic.cs".
  • Copied the file "\PCAN-Basic\x64\PCANBasic.dll" into the folder "C:\Windows\SysWOW64"
  • Copied the file "\PCAN-Basic\x86\PCANBasic.dll" into the folder "C:\Windows\System32"
And then, in my code, I just create a new Worker with the parameters PcanChannel.Usb01 and Bitrate.Pcan500.
And when I try to do "myWorker.Start()", I get following error:

System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'

Error: The type initializer for 'Peak.Can.Basic.Api' threw an exception.
StackTrace: at Peak.Can.Basic.Api.SetValue(PcanChannel channel, PcanParameter parameter, UInt32 buffer)
at J8k3ueSJrCOMJAl558X.eWVAVDSUPe5JhLFLlvB.vdKSB42xLx(Boolean )
at J8k3ueSJrCOMJAl558X.eWVAVDSUPe5JhLFLlvB.SetBitrateAdapting(Boolean value)
at J8k3ueSJrCOMJAl558X.eWVAVDSUPe5JhLFLlvB.ytnSwZS38P(Boolean )
at Peak.Can.Basic.Worker.Start(Boolean ignoreBitrateCheck, Boolean deactivateReading, Boolean deactivateBroadcasting)
at PcanDll.PCANManager.ConnectWorker(PcanChannel canChannel, Object baudrate, Boolean canFd, String& errorDescription) in D:\Documents\02-Csharp\PcanDll_FrameWork_4_8\PcanDll\PcanDll\PcanDll.cs:line 145


But everything was fine before I had performed the update.
Anyone would have an idea?

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: Issue after updating Peak.PCANBasic.NET to version 4.10.0.964

Post by K.Wagner » Fri 20. Dec 2024, 10:20

Hello,

First of all, you should always use the PEAK-Drivers Setup to install the PCAN-Basic files. Manually copying the files to the system folders can end in copying the files wrong, like in your case:
LudovicC wrote:
Fri 20. Dec 2024, 10:04
Copied the file "\PCAN-Basic\x64\PCANBasic.dll" into the folder "C:\Windows\SysWOW64"
Copied the file "\PCAN-Basic\x86\PCANBasic.dll" into the folder "C:\Windows\System32
The x86 version of the DLL belong to the folder C:\Windows\SysWOW64
The x64 version of the DLL belong to the folder C:\Windows\System32
LudovicC wrote:
Fri 20. Dec 2024, 10:04
Copied in each project's folder the file "\PCAN-Basic\Include\PCANBasic.cs".
Second, if you use the NuGet Pacakge you do not need the PCANBasic.cs file. You can read the How-and-Tos section of the documentation for more information.
Best regards,
Keneth

LudovicC
Posts: 9
Joined: Thu 19. Sep 2024, 16:44

Re: Issue after updating Peak.PCANBasic.NET to version 4.10.0.964

Post by LudovicC » Fri 20. Dec 2024, 11:17

Hello Keneth,

Thanks a lot for your fast answer!
Installing the drivers 4.6 solved it.
I will definitely keep this best practice in the future.

Now I can test this new TPCANParameter.PCAN_DEVICE_GUID. Which lead to other question, but I will make a new post to keep it clean.

kundewayne

Re: Issue after updating Peak.PCANBasic.NET to version 4.10.0.964

Post by kundewayne » Mon 6. Jan 2025, 10:38

K.Wagner wrote:
Fri 20. Dec 2024, 10:20
Hello,

First of all, you should always use the PEAK-Drivers Setup to install the PCAN-Basic files. Manually copying the files to the system folders can end in copying the files wrong, like in your case:
LudovicC wrote:
Fri 20. Dec 2024, 10:04
Copied the file "\PCAN-Basic\x64\PCANBasic.dll" into the folder "C:\Windows\SysWOW64"
Copied the file "\PCAN-Basic\x86\PCANBasic.dll" into the folder "C:\Windows\System32
The x86 version of the DLL belong to the folder C:\Windows\SysWOW64
The x64 version of the DLL belong to the folder C:\Windows\System32
LudovicC wrote:
Fri 20. Dec 2024, 10:04
Copied in each project's folder the file "\PCAN-Basic\Include\PCANBasic.cs".
Second, if you use the NuGet Pacakge you do not need the PCANBasic.cs file. You can read the How-and-Tos section of the documentation for more information.
I appreciate you pointing out the proper PCAN-Basic file installation process! In the future, I'll make sure to avoid manual copying and utilize the PEAK-Drivers Setup. Additionally, I will see that the NuGet Package choice removes the requirement for the PCANBasic.cs file. Thank you for the clarity!

Post Reply