Christree
Christree

Reputation: 11

I have issues with publishing my WInForms app with 3rd party CLIs. How do I avoid the "The specified module could not be found" exception?

I'm new to C# and programming outside Matlab in general, and have spent a long time looking into this issue.

My program uses several 3rd party CLIs and also some native C DLLs, all for x64. They are all in the correct folder and referenced, and the build target platform for my program is also set for x64. Target framework is .NET 4.7.2. in VS2022. The program works fine in both debug and release mode IF I choose "Any CPU" next to the debug/release dropdown. (This confuses me and might be the source of the error. Could you please help me understand the difference between build target platform and debug/release target platform, and why does one have to be x64 and the other "Any CPU"? - it doesn't compile if I set it otherwise, ie. both to x64.)

When I was debugging, I found that one of the CLIs can't load if a DLL called "PrivateInternal" from the SDK is not in the folder. So I put it in the folder, however I can't reference it and I dont know what it does. The program works fine inside VS as long as "PrivateInternal" is in the folder.

My problem is: When I publish the app, I can install it and everything. But when I press a button that initiates code with the mentioned CLI above, it returns the "The specified module could not be found" exception.

System.IO.FileNotFoundException: Could not load file or assembly 'Thorlabs.MotionControl.DeviceManagerCLI.dll' or one of its dependencies. The specified module could not be found. File name: 'Thorlabs.MotionControl.DeviceManagerCLI.dll' at StageControlUI.Form1.GetSerialNumbers() at StageControlUI.Form1.btn_connect_Click(Object sender, EventArgs e)...

I suspect its due to the "PrivateInternal" DLL not being referenced , but it could also be because Im somehow publishing it wrong. I have looked into publishing issues and considerations for WinForms and CLIs (for example Debugging Assembly Loading Failures). But I would like some guidance on how to proceed from my current standpoint?

Upvotes: 1

Views: 154

Answers (1)

David
David

Reputation: 160

With AnyCPU/x64 you are talking about the target platform your application should be running on. If you build your project on AnyCPU for example you want your application to run on any device regardless of the architecture of the CPU.

My guess why your module is not found is that you didnt choose the right build platform in the configuration manager for your project!

To open the configuration manager: right click on solution -> Configuration Manager...

Here you need to select the decired building mode and the platform you want to build. Now check if all Project have the right mapping. Hope this helps.

Upvotes: -1

Related Questions